Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

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.

Knowing nothing about your actual data points, one can only guess. 
*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[1]:=
data = Transpose[{Range[10], 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[4], Point /@ data,
      RGBColor[1, 0, 0], Point[sp[1.4]]}];

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

Out[4]=
{2.4, 0.782727}

[...graphics deleted...]

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

In[1]:=
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[4], Point /@ data, Red, Point[sp[1.4]]}];

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

Out[4]=
{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