0% found this document useful (0 votes)
80 views

Raport: Universitatea Tehnică A Moldovei Fcim Catedra Automatica Si Tehnologii Informationale

This document reports on a lab work to construct the Lagrange polynomial that approximates a given function. The task was to build the Lagrange polynomial Ln(x) and calculate the value of the function f(x) at a point x using the interpolation polynomial. The program listing shows the code used, which takes x and y values as input, calculates the Lagrange coefficients, displays the polynomial and verifies the values. The conclusion states that the lab work was completed by constructing the Lagrange interpolation polynomial for a given function and developing a program to calculate the function value at a point using the polynomial.

Uploaded by

OpreaEugen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Raport: Universitatea Tehnică A Moldovei Fcim Catedra Automatica Si Tehnologii Informationale

This document reports on a lab work to construct the Lagrange polynomial that approximates a given function. The task was to build the Lagrange polynomial Ln(x) and calculate the value of the function f(x) at a point x using the interpolation polynomial. The program listing shows the code used, which takes x and y values as input, calculates the Lagrange coefficients, displays the polynomial and verifies the values. The conclusion states that the lab work was completed by constructing the Lagrange interpolation polynomial for a given function and developing a program to calculate the function value at a point using the polynomial.

Uploaded by

OpreaEugen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Universitatea Tehnic a Moldovei

FCIM
Catedra Automatica si Tehnologii Informationale

RAPORT
la lucrarea de laborator nr. 3

la Metode numerice

Tema: Polinomul Lagrange

A efectuat:
A verificat: Eeleonora Tutunaru

Chiinu 2015
Sarcina lucrrii:
- Sa se construeasca polinomul Lagrange Ln(x) ce aproximeaza functia
data.
- Sa se calculeze valoarea functiei f(x) intr-un punct x,utilizind polinomul
de interpolare Lagrange .

X 1 2 3
Y 1 8 27

Listingul programului:
#include <iostream>
#include <math>
#include <conio>
#include <stdlib>

float x[100],y[100];

int main()
{
float q[100],b[100],ln[100],im;
int i,j,k,m,n;
cout<<"\n\n Introdu dimensiunea matricilor ";
cin>>n;
cout<<"\n\n Introdu valorile lui x: ";

for(i=0; i<n; i++)


{
cin>>x[i];

if(i>=1)
{
for(j=0;j<=i-1;j++)
{
if(x[i]==x[j]) {cout<<"\n Valorile coincid, punctele
nu sut distincte!";getch();exit(0);}
}
}
}
cout<<"\n Introdu valorile lui y: ";
for(i=0; i<n; i++)
{
cin>>y[i];
if(i>=1)
{
for(j=0;j<=i-1;j++)
{
if(y[i]==y[j]) {cout<<"\n Valorile coincid,
punctele nu sut distincte!";getch();exit(0);}
}
}
}
for(i=0;i<n;i++)
{
im=1;
for(j=0;j<n;j++)
{
b[j]=0;
q[j]=0;
if (i!=j)im=im*(x[i]-x[j]);
}
if (i==0)
{
q[1]=1;
q[0]=-1*x[1];
} else
{
q[1]=1;
q[0]=-1*x[0];
}
b[1]=q[1];
b[0]=q[0];
for(j=1;j<n;j++)
{
if ((i!=j)&&((j!=1)||(i!=0)))
{
for(k=n;k>=1;k--) b[k]=q[k-1];
b[0]=0;
for(m=0;m<n;m++)
{
b[m]=b[m]+(q[m]*-1*x[j]);
}
for(m=0;m<n;m++)q[m]=b[m];
}
}
im=y[i]/im;
for(k=0;k<n;k++)
{
b[k]*=im;
ln[k]+=b[k];
}
}
cout<<"\nPolinomul ";
i=n-1;
cout<<ln[i]<<"*x^"<<i;
for (i=n-2;i>0;i--)
if (ln[i]<0)cout<<ln[i]<<"*x^"<<i;else
cout<<"+"<<ln[i]<<"*x^"<<i;
i=0;
if (ln[i]<0)cout<<ln[i];else cout<<"+"<<ln[i];
float v=0,f=0;
cout<<"\nVerificare:\n";

for(j=0;j<n;j++)
{
cout<<"Ln("<<x[j]<<")=";
f=0;
v=x[j];
for(i=0;i<n;i++)
f=f+ln[i]*pow(v,i);
cout<<f<<"\n";
}
cout<<"\n Introduceti punctul in care se va calcula valoarea
functiei:";

cin>>v;
f=0;
for(i=0;i<n;i++)
f=f+ln[i]*pow(v,i);
cout<<"\nValoare functiei in punctul x="<<v<<" este "<<f;
getch();
}

Figura 1 Afisarea polinomului si valoarea functiei in punctul 13

Concluzii:
Efectuind acesta lucrare de laborator am construit polinomul de interpolare Lagrange
ce aproximeaza o functie data,am elaborat programul care calculeaza valoare functiei
f(x) intr-un punct x, utilizind polinomul de interpolare Lagrange.

You might also like