EXPLORING CYBERSPACE…

Lagrange’s Formula

June 10, 2009 · Leave a Comment

#include<conio.h>
#include<stdio.h>
#include<dos.h>
void main()
{
 clrscr();
 float ax[50],ay[50],nr,dr,y=0,x;
 int I,j,n;
 printf(“\nEnter the no of terms:”);
 scanf(“%d”,&n);
 for(i=0;i<n;i++)
 {
 printf(“\nEnter the value for x and y::”);
 scanf(“%f %f”,&ax[i],&ay[i]);
 }
 printf(“\nEnter the value for which function is to be calculated:”);
 scanf(“%f”,&x);
 for(i=0;i<n;i++)
 {
 nr=dr=1;
 for(j=0;j<n;j++)
 {
 if(j!=i)
 {
 nr=nr*(x-ax[j]) ;
 dr=dr*(ax[i]-ax[j]);
 }
 }
 y=y+(nr/dr)*ay[i];
 }
 printf(“\n\nThe value for function at %f is %f”,x,y);
 delay(3000);
}

Categories: Numerical Techniques · Programming in C

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment