The Laplace interpolation method is not a very practical interpolation method. It is usually used in piecewise interpolation. When there are too many interpolation nodes, the data is unstable.
# Include "lags. h"
# Include "myAssert. h"
# Include <stdlib. h>
# Include <stdio. h>
Type lagrangeInsert (Type * xArr, Type * yArr, Type x, int n)
{
Type tmpSum = Type_Zero, sum = Type_Zero;
Int I = 0, j = 0;
Asserts (xArr! = NULL, "xArr passed in is null/n ");
Asserts (yArr! = NULL, "yArr passed in is null/n ");
For (I = 0; I <n; I ++)
{
TmpSum = yArr [I];
For (j = 0; j <n; j ++)
If (j! = I) tmpSum * = (x-xArr [j])/(xArr [I]-xArr [j]);
Sum + = tmpSum;
}
Return sum;
}
/* Test */
# Include "lags. h"
# Include "stdio. h"
# Include "string. h"
Void main ()
{
Double x1 [] = {0.4, 0.5, 0.6, 0.7 };
Double y1 [] = {-0.916291,-0.693147,-0.510826,-0.356675 };
Double ans;
Clrscr ();
Ans = lagrangeInsert (x1, y1, 0.54, 4); // 4 indicates that the interpolation is a polynomial of four times.
Printf ("The answer of lagrangeInsert is: % f/n", ans );
}