// Lagrange interpolation // driver program for polint.cpp #include #include #include #include "polint.cpp" using namespace std; int main () { const int n = 11; int nint; double xi[n] = {-1.0,-0.8,-0.6,-0.4,-0.2,0.0,0.2,0.4,0.6,0.8,1.0}; double yi[n] = {0.0385,0.0588,0.1,0.2,0.5,1.0,0.5,0.2,0.1,0.0588,0.0385}; double x, y; x = 0.32; // nint: points for interpolation ("order of interpolation" = nint - 1) nint = 4; y = polint(x, xi, yi, n, nint); cout.setf(ios::fixed | ios::showpoint); cout.precision(5); cout << "order = " << nint-1 << " x = " << x << " y = " << y << endl; system ("pause"); return 0; } /* Test output order = 3 x = 0.32000 y = 0.29600 */