/*************************************************** * Program to demonstrate Lagrange interpolation * * of Function SIN(X) in double precision * * ------------------------------------------------ * * Reference: BASIC Scientific Subroutines, Vol. II * * By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1].* * * * C++ version by J-P Moreau, Paris * * (www.jpmoreau.fr) * * ------------------------------------------------ * * SAMPLE RUN: * * * * Lagrange interpolation of SIN(X): * * * * Input X: 0.5 * * Order of interpolation: 4 * * * * SIN(X) = 0.47942552 (exact value: 0.47942554) * * * ***************************************************/ #include #include // Label: e100 double XL[10]; double X[15], Y[15]; double xx,yy; int iv,n; /******************************************************* * Lagrange interpolation subroutine * * ---------------------------------------------------- * * n is the level of the interpolation ( Ex. n=2 is * * quadratic ). v is the total number of table values. * * X(i), Y(i) are the coordinate table values, Y(i) * * being the dependant variable. The X(i) may be arbi- * * trarily spaced. x is the interpolation point which * * is assumed to be in the interval with at least one * * table value to the left, and n to the right. If this * * is violated, n will be set to zero. It is assumed * * that the table values are in ascending X(i) order. * *******************************************************/ void Interpol_Lagrange() { //Labels: e100,e200,e300,e400 int i,j,k; // Check to see if interpolation point is correct if (xx < X[1]) goto e100; if (xx <= X[iv-n]) goto e200; // An error has been encountered e100: n=0 ; return; // Find the relevant table interval e200: i=0; e300: i++; if (xx > X[i]) goto e300; i--; // Begin interpolation for (j=0; j