/*Quadratic Interpolation*/
#include<stdio.h>
#include<conio.h>
void main()
{
float x,b0,b1,b2,x0,x1,x2,f,f0,f1,f2;
clrscr();
puts("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
puts("Quadratic Interpolation");
puts("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
printf("Enter value of x0,f(x0)");
scanf("%f %f",&x0,&f0);
puts("----------------------------------------");
printf("Enter value of x1,f(x1)");
scanf("%f %f",&x1,&f1);
puts("----------------------------------------");
printf("Enter value of x2,f(x2)");
scanf("%f %f",&x2,&f2);
puts("----------------------------------------");
printf("Enter value of x");
scanf("%f",&x);
puts("----------------------------------------");
b0=f0;
b1=(f1-f0)/(x1-x0);
b2=(((f2-f1)/(x2-x1))-((f1-f0)/(x1-x0)))/(x2-x0);
f=b0+b1*(x-x0)+b2*(x-x0)*(x-x1);
printf("b0=%f\nb1=%f\nb2=%f\nf(x)=%f",b0,b1,b2,f);
puts("\n----------------------------------------");
getch();
}
Output:-
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Quadratic Interpolation
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Enter value of x0,f(x0)
1 0
----------------------------------------
Enter value of x1,f(x1)
4 1.5863
----------------------------------------
Enter value of x2,f(x2)
6 1.7918
----------------------------------------
Enter value of x
2
----------------------------------------
b0=0.000000
b1=0.528767
b2=-0.085203
f(x)=0.699173
----------------------------------------
No comments:
Post a Comment