Wednesday, 23 April 2014

Program to solve interpolation formula using Lagrange interpolation method

Here is a C program to solve interpolation formula using Lagrange interpolation method.

 #include<stdio.h>  
 #include<conio.h>  
 int main()  
 {  
 int n,i,j;  
 float x1,x[10],f[10],sum=0,pf;  
 //clrscr();  
 printf("enter the order of polynomial :\n");  
 scanf("%d",&n);  
 printf("enter the value to be find :\n");  
 scanf("%f",&x1);  
 printf("enter values for xi & f(xi) :\n");  
 for(i=0;i<n;i++)  
 {  
  scanf("%f",&x[i]);  
  scanf("%f",&f[i]);  
 }  
 sum=0;  
 for(i=0;i<(n+1);i++)  
 {  
  pf=1;  
  for(j=0;j<(n+1);j++)  
  {  
   if(j!=i)  
    pf=pf*(x1-x[j])/(x[i]-x[j]);  
    }  
  sum=sum+f[i]*pf;  
 }  
 printf("f(%.2f)=%.2f\n",x1,sum);  
 getch();  
 }  

No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2016