This project has moved and is read-only. For the latest updates, please go here.

(CubicSpline) Could I get value X from value Y?

Sep 12, 2014 at 5:09 PM
Edited Sep 12, 2014 at 5:57 PM
I made a simple curve like this.
double[] px = new double[] { 0.0, 5.0, 10.0 };
double[] py = new double[] { 0.0, 3.0, 10.0 };
CubicSpline spline1 = CubicSpline.InterpolateNatural(px, py);
axis-x is time, axis-y is value. and get value y coding
double value = spline1.Interpolate(x);
But sometime i need to know how long the value will become specify value. And I create this
CubicSpline spline2 = CubicSpline.InterpolateNatural(py, px);
Testing with these code
Console.WriteLine(spline2.Interpolate(spline1.Interpolate(0)));    // output: 0
Console.WriteLine(spline2.Interpolate(spline1.Interpolate(5)));    // output: 5
Console.WriteLine(spline2.Interpolate(spline1.Interpolate(10)));  // output: 10

Console.WriteLine(spline2.Interpolate(spline1.Interpolate(2.0))); // output: 1.553190912
Console.WriteLine(spline2.Interpolate(spline1.Interpolate(3.0))); // output: 2.51721969371429
Its correct at Key point, others are not my want.

Is there any function i could use?
Sep 16, 2014 at 3:09 PM
Maybe combine it with a root finder?