// FUNCTION TO CARRY OUT LAGRANGE INTERPOLATION
// FOR CW 1 2001/2002
// *x holds x values, *fx holds function values, ‘value’
is known x value
float Lagrange (float *x, float *fx, float value)
{
int
i,j,product,sum=0.0;
// Lagrange algorithm - Eqn. 2.10
// saw code similar to this in lecture
for (i=0;i<4;i++)
{
product=fx[i];
//Correctly initialising product variable
for
(j=0;j<4;j++)
{
if
(i!=j) // Ensure that i=j case is not
used
product=product*((value-x[j])/(x[i]-x[j])); // Calculate product
}
sum=sum+product; // Add product
to running total
}
return (sum);
}