To understand and use Lagrange’s Interpolation for a polynomial to determine functional value of data

0 32

Program to understand and use Lagrange’s Interpolation for a polynomial to determine functional value of data

Lagrange’s Interpolation for a polynomial is used to determine nature of a polynomial with its degree based upon number of input values. As a polynomial is constructed, it is matched for the given data value to verify or to compute its functional value. This is all done by programming for Lagrange’s Polynomial.


/* To calculate the functional value using Lagrange’s Interpolation */

#include
#include
#include
#include

void main()
{
double n, a, k, value, x[10], f[10], p[10];
clrscr();
cout<<“Enter the no of data:\t”;
cin>>n;

cout<<<<“Enter the input values:\t”;
for(int i=1;i<=n;i++)
{
cin>>x[i];
cout<<<“\t”;
}

cout<<<<“Enter the respective functional values:\t”;
for(i=1;i<=n;i++)
{
cin>>f[i];
cout<<<“\t”;
}

cout<<<“Supply the data whose functional value is to be determined:\t”;
cin>>a;

for(k=1;k<=n;k++)
{
p[k]=1.0;
for(i=1;i<=n;i++)
{
if(i!=k)
p[k]=p[k]*(a-x[i])/(x[k]-x[i]);
}
}

value=0.0;
for(i=1;i<=n;i++)
{
value=value+(p[i]*f[i]);
}

cout<<<<“Required functional value for “<<<” is “<<<“.”;

getch();
}


To understand and use Lagrange’s Interpolation for a polynomial to determine functional value of data in C++ Programming Language for Numerical Methods for Engineering Students

You might also like More from author

Leave a Reply

Font Resize