This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Interpolation in Eigen

Tags: None
(comma "," separated)
A32167
Registered Member
Posts
3
Karma
0

Re: Interpolation in Eigen

Mon Feb 25, 2013 1:23 pm
Oh, yes, indeed. Providing the knots manually is the right way to proceed. Thanks for helping with that!
Hauke
Registered Member
Posts
109
Karma
3
OS

Re: Interpolation in Eigen

Mon Feb 25, 2013 3:03 pm
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
vpham
Registered Member
Posts
1
Karma
0

Re: Interpolation in Eigen

Tue Jan 17, 2017 1:42 am
#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


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]