Search & Find out

Thursday, December 3, 2009

Lagranges Interpolation Method

#include "stdio.h"
#include "conio.h"


void main()

{
 int i,n,i1,i2;
 float x[100],fx[100],x1,fx1=0,nu,de;
 clrscr();

 printf("Welcome to Lagranges Interpolation Method\n\n");

 printf("Enter the no. of X's do you wish to give?  ");
 scanf("%d",&n);

 for(i=0;i
 {
   printf("Enter the values of X%d\n",i);
   scanf("%f",&x[i]);
   printf("Enter the values of f(x%d)\n",i);
   scanf("%f",&fx[i]);
 }

 printf("\n\nEnter the value of x to find f(x)\n\n");
 scanf("%f",&x1);

 for(i=0;i
 {


   for(i1=0,nu=1;i1
   {
     if(x[i]==x[i1])
     {
       continue;
     }
      nu=((x1-x[i1]) * (nu));

   }

   for(i2=0,de=1;i2
   {

     if(x[i]==x[i2])
     {
       continue;
     }
       de=((x[i]-x[i2]) * (de));

   }

      fx1=((nu/de)*fx[i]) + fx1;

}

printf("The table is\n\n");
printf("\tx\t\t\tfx\n\n");
for(i=0;i
{
  printf("\t%f\t\t%f\n",x[i],fx[i]);

}

 printf("\t%f\t\t%f\n",x1,fx1);


getch();
}


Download the executable (.exe)  file for this program..
download



0 comments:

Post a Comment

 

My Blog List

Term of Use