Interpolation is a method of computing a new data point from a set of discrete set of known data points. This is frequently required in science and engineering, where one could have a number of data points obtained by measurement or simulation, representing the value of the function for a limited number of points of the independent variable. It is often required to estimate, or interpolate, the value of the function for a set of intermediate values of the independent variable.
The specific example estimates the Legendre polynomial,
lagint.f90: Function to perform Lagrange interpolationinterp_test.f90: Fortran source code - driver forlagint.f90
Intel Fortran Compiler (ifort):
ifort -o interp_test.x lagint.f90 interp_test.f90 -O2GNU Fortran Compiler (gfortran):
gfortran -o interp_test.x lagint.f90 interp_test.f90 -O2 x P_5(x) Exact
-1.000000 -1.000000 -1.000000
-0.777778 0.417209 0.417162
-0.555556 0.041927 0.041914
-0.333333 -0.333316 -0.333333
-0.111111 -0.196459 -0.196464
0.111111 0.196459 0.196464
0.333333 0.333316 0.333333
0.555556 -0.041927 -0.041914
0.777778 -0.417209 -0.417162
1.000000 1.000000 1.000000