I need help C programming code the Lagrange portion of the problem, specifically
ID: 3779649 • Letter: I
Question
I need help C programming code the Lagrange portion of the problem, specifically finding the polynomial.
Explanation / Answer
#include<stdio.h>
#include<conio.h>
#define MaxN 90
int main()
{
float x_array[MaxN+1], y_array[MaxN+1], numr, denom, x, y=0;
int i, j, n;
printf("Enter value of n: ");
scanf("%d", &n);
printf("Enter values of x and y: ");
for(i=0; i<=n; i++)
scanf("%f%f", &x_array[i], &y_array[i]);
printf("Enter x at which value of y is to be calculated: ");
scanf("%f", &x);
for (i=0; i<=n; i++)
{
numr=1;
denom=1;
for (j=0; j<=n; j++)
if(j!=i)
{
numr *= x-x_array[j];
denom *= x_array[i]-x_array[j];
}
y+=(numr/denom)*y_array[i];
}
printf("When x=%4.1f y=%7.1f ",x,y);
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.