How to find coefficients of polynomial equation?
问题 Given two points in the x, y plane: x, f(x) 1, 3 2, 5 I can interpolate them using Lagrange and find f(1.5) , which result in 4 . Thinking a little I managed to find a way to discover the coefficients of the equation: void l1Coefficients(const vector<double> &x, const vector<double> &y) { double a0 = y[0]/(x[0]-x[1]); double a1 = y[1]/(x[1]-x[0]); double b0 = (-x[1]*y[0])/(x[0]-x[1]); double b1 = (-x[0]*y[1])/(x[1]-x[0]); double a = a0 + a1; double b = b0 + b1; cout << "P1(x) = " << a << "x +