mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-21 21:11:57 +03:00
18 Oct
This commit is contained in:
parent
9c3f920403
commit
1f971098c4
45
Computer Oriented Statistical Methods/lagrange_theorem.C
Normal file
45
Computer Oriented Statistical Methods/lagrange_theorem.C
Normal file
@ -0,0 +1,45 @@
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
#include<stdlib.h>
|
||||
#include<math.h>
|
||||
void main()
|
||||
{
|
||||
float x[20],y[20],a,sum,p;
|
||||
int n,i,j;
|
||||
clrscr();
|
||||
printf("Enter the no of entry to insert->");
|
||||
scanf("%d",&n);
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
printf("enter the value of x%d->",i);
|
||||
scanf("%f",&x[i]);
|
||||
printf("enter the value of y%d->",i);
|
||||
scanf("%f",&y[i]);
|
||||
}
|
||||
printf("\n X \t\t Y \n");
|
||||
printf("----------------------------\n");
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
printf("%f\t",x[i]);
|
||||
printf("%f\n",y[i]);
|
||||
}
|
||||
printf("\nenter the value of x for interpolation:");
|
||||
scanf("%f",&a)
|
||||
sum=0;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
p=1.0;
|
||||
for(j=0;j<n;j++)
|
||||
{
|
||||
|
||||
if(i !=j)
|
||||
{
|
||||
p=p*(a-x[j])/(x[i]-x[j]);
|
||||
}
|
||||
sum=sum+y[i]*p;
|
||||
}
|
||||
printf("ans is->%f",sum);
|
||||
getch();
|
||||
|
||||
}}
|
Loading…
Reference in New Issue
Block a user