Registered Member
|
Oh, yes, indeed. Providing the knots manually is the right way to proceed. Thanks for helping with that!
|
Registered Member
|
To potential future posters on this thread ...
please consider opening a new thread for new questions for the sake of clarity and readability. Thanks, Hauke |
Registered Member
|
#include <vector>
#include <iostream> #include <Eigen/Core> #include <unsupported/Eigen/Splines> using namespace Eigen; double uvalue(double x, double low, double high) { return (x - low)/(high-low); } VectorXd uvalues(VectorXd xvals) { const double low = xvals.minCoeff(); const double high = xvals.maxCoeff(); for (int i=0; i<xvals.size(); ++i) { xvals(i) = uvalue(xvals(i), low, high); } return xvals; } int main(int argc, char* argv[]) { typedef Spline<double,1> Spline2d; const VectorXd xvals = (VectorXd(5) << 1,2,3,4,6).finished(); const VectorXd yvals = xvals.array().square(); const Spline2d spline = SplineFitting<Spline2d>::Interpolate(yvals.transpose(), 3, uvalues(xvals).transpose()); const double step = 0.1; for (double x = 1; x < 6 + 0.5*step; x += step) { std::cout << "(" << x << "," << spline(uvalue(x, xvals.minCoeff(), xvals.maxCoeff())).transpose() << ")\n"; } std::cout << std::endl; } Hi Hauke, I find your code is a great example for the eigen spline. However, I am very new to the software. How do I deal with the irregular x values such as (1/12,1/4,1/2,1,2,5,10,15,20) for the above code? Many thanks. Cheers, Van |
Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]