Derive an interpolating polynomial using Gregory-Newton and print coefficients o
ID: 653170 • Letter: D
Question
Derive an interpolating polynomial using Gregory-Newton and print coefficients of the polynomial on screen
Please include a screen shot of the code running
Given the following data set: Develop one code to: Derive an interpolating polynomial using the Gregory-Newton, and print the coefficients of the polynomial on screen. Based on the expression developed in, find the value of x for f(x)=0.4815 by using the Bisection method with eps=0.0001. Print that x value on screen. problem is the same as that to find the root of f(x)-0.4815=0.Explanation / Answer
/*Newton-Gregory Backward Interpolation Formula C Program*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void bisection(float x0,float x1)
{
int i = 1;
float x2;
double f1,f2,f0,t; clrscr();
printf(" __________________________________________________________________ "); printf(" iteration x0 x1 x2 f0 f1 f2"); printf(" ___________________________________________________________________ "); do
{ x2=(x0+x1)/2;
f0=F(x0);
f1=F(x1); f2=0.4815;
printf(" %d %f %f %f %lf %lf %lf", i, x0,x1,x2,f0,f1,f2); if(f0*f2<0) { x1=x2; }
else { x0=x2; }
i++; }while(fabs(f2)>ESP); printf(" __________________________________________________________ "); printf(" App.root = %f",x2);
}
void main()
{
int i,j,k,n;
float x[10],y[10],d[10][10],X,u,h,fact=1.0,sum=0.0,prod=0.0;
clrscr();
printf("Enter the size: ");
scanf("%d",&n);
printf("enter the value of X: ");
scanf("%f",&X);
for(i=1;i<=n;i++)
{
printf("Enter x[%d]: ",i);
scanf("%f",&x[i]);
printf("Enter y[%d]: ",i);
scanf("%f",&y[i]);
}
i=2;
while(X>x[i])
i++;
k=i;
u=(X-x[k])/(x[k]-x[k-1]);
for(j=1;j<=(n-1);j++)
{
for(i=j+1;i<=n;i++)
{
if(j==1)
d[i][j]=y[i]-y[i-1];
else
d[i][j]=d[i][j-1]-d[i-1][j-1];
}
}
printf("Backward difference Table: ");
for(i=1;i<=n;i++)
{
for(j=1;j<n;j++)
{
if(i==1)
printf(" ");
else if(j<i)
printf("%f ",d[i][j]);
else
printf(" ");
}
printf(" ");
}
sum=y[k];
for(i=1;i<=(n-1);i++)
{
prod=1.0;
for(j=0;j<=(i-1);j++)
prod=prod*(u+j);
fact=1;
for(j=1;j<=i;j++)
fact=fact*j;
sum=sum+((prod*d[k][i])/fact);
}
printf("Integral value=%f",sum);
for(i=1;i<=n;i++)
{
bisection(x[i],x[i+1]);
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.