A C++ numerical method library contains Least Square Polynomial Approximation, Gregory-Newton Interpolation, and Numerical Integration.
#include "numlib.h"
std::vector<double> xdata{1, 2, 3, 4, 5};
std::vector<double> ydata{1, 8, 9, 64, 125};
dataset ds(xdata, ydata);
# returns polynomial coefficient
std::vector<double> coef;
coef = ds.leastSquareCoef();
coef should be {0, 0, 0, 1} which represents 0x^0+0x^1+0x^2+1x^3.
# returns y value
double yValue;
yValue = ds.leastSquareY(6);
yValue should be 6^3 = 216.
Please refer to the explanation of Gregory-Newton Forward Difference.
#returns interpolation value
yValue = ds.gregoryNewton(6);
yValue should also be 216.
pending...
Pull requests are welcome! Feel free to contact me via email.