_test_eigen_spline.cxx
Go to the documentation of this file.
1 // https://forum.kde.org/viewtopic.php?f=74&t=98871
2 // https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=736985
3 #include <vector>
4 #include <iostream>
5 
6 #include <Eigen/Core>
7 #include <unsupported/Eigen/Splines>
8 
9 using namespace Eigen;
10 
11 double uvalue(double x, double low, double high)
12 {
13  return (x - low)/(high-low);
14 }
15 
16 VectorXd uvalues(VectorXd xvals)
17 {
18  const double low = xvals.minCoeff();
19  const double high = xvals.maxCoeff();
20  for (int i=0; i<xvals.size(); ++i)
21  {
22  xvals(i) = uvalue(xvals(i), low, high);
23  }
24  return xvals;
25 }
26 
27 int main(int argc, char* argv[])
28 {
29  typedef Spline<double,1> Spline2d;
30 
31  const VectorXd xvals = (VectorXd(5) << 1,2,3,4,6).finished();
32  const VectorXd yvals = xvals.array().square();
33  const Spline2d spline = SplineFitting<Spline2d>::Interpolate(yvals.transpose(), 3, uvalues(xvals).transpose());
34 
35  const double step = 0.1;
36  for (double x = 1; x < 6 + 0.5*step; x += step)
37  {
38  const double uv = uvalue(x, xvals.minCoeff(), xvals.maxCoeff());
39  std::cout << "(" << x << "," << spline(uv).transpose() << "," << spline.derivatives<1>(uv) << ")\n";
40  }
41  std::cout << std::endl;
42 }
VectorXd uvalues(VectorXd xvals)
int main(int argc, char *argv[])
def Interpolate(x1, y1, x2, y2, yvalue)
Definition: HandyFuncs.py:200
list x
Definition: train.py:276
double uvalue(double x, double low, double high)
QTextStream & endl(QTextStream &s)