       Re: Evaluate a spline function

• To: mathgroup at smc.vnet.net
• Subject: [mg74081] Re: Evaluate a spline function
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Fri, 9 Mar 2007 02:00:00 -0500 (EST)
• Organization: The Open University, Milton Keynes, UK
• References: <esola2\$ef5\$1@smc.vnet.net>

```Ivan wrote:
> Hi,
> I have used the SplineFit to interpolate my data points for a curve
> y(x) and now
> would like to get the interpolated value between my data points.
> Is there a easy way to evaluate y(x) by directly inputting the value
> of x?
>
> i.e.
>
> y = SplineFit["data.dat",Cubic]
>
> how to get y(x) with x being the value of variable instead of the
> order of the data points.

*SplineFit* returns a parametric function. If you have a single-valued
curve (as below), you just have to rescale the value of x to fit the
value of the spline parameter, say t.

In:=
data = Transpose[{Range, Table[Random[Integer, {0, 5}], {10}]}];
Needs["NumericalMath`SplineFit`"]
sp = SplineFit[data, Cubic]
sp[1.4]
ParametricPlot[sp[t], {t, 0, 9}, PlotRange -> All,
Compiled -> False, Epilog ->
{AbsolutePointSize, Point /@ data,
RGBColor[1, 0, 0], Point[sp[1.4]]}];

Out=
SplineFunction[NumericalMath`SplineFit`Cubic, {0., 9.}, <>]

Out=
{2.4, 0.782727}

[...graphics deleted...]

However, if your curve is multi-valued, as in the example below, you
cannot. For instance,

In:=
data = {{0, 0}, {1, 2}, {-1, 3}, {0, 1}, {3, 0}};
Needs["NumericalMath`SplineFit`"]
sp = SplineFit[data, Cubic]
sp[1.4]
ParametricPlot[sp[t], {t, 0, 4}, PlotRange -> All, Compiled -> False,
Epilog -> {AbsolutePointSize, Point /@ data, Red, Point[sp[1.4]]}];

Out=
SplineFunction[Cubic, {0., 4.}, <>]

Out=
{0.265143, 2.70171}

[...graphics deleted...]

Regards,
Jean-Marc

```

• Prev by Date: Re: "Transparency" with respect to differentiation
• Next by Date: Re: How to rotate AxesLabel ?
• Previous by thread: Re: Evaluate a spline function
• Next by thread: Re: Evaluate a spline function