Lagrange Interpolation
CSC-212 · Semester III · Numerical Methods
#include <stdio.h> int main() { double xp[3] = {0, 1, 2}; double yp[3] = {1, 4, 9}; double x = 1.5; double y = 0; for (int i = 0; i < 3; i++) { double L = 1; for (int j = 0; j < 3; j++) { if (j != i) L *= (x - xp[j]) / (xp[i] - xp[j]); } y += yp[i] * L; } printf("P(%.1f) = %.4f\n", x, y); return 0; }
Write some code, then press Run. Stdout and errors appear here.