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: [mg74104] Re: Evaluate a spline function
  • From: "Dana DeLouis" <dana.del at gmail.com>
  • Date: Sat, 10 Mar 2007 06:51:46 -0500 (EST)

Hi.  As others have mentioned, a Spline function is a Parametric Equation.
When given a value such as 3.5 in a Spline Function, the integer part (3) is
used to determine "Which" equation to use, and the fractional part (.5) is
used in that equation to calculate x & y.  I use the variable "p" to help
remind me that it is a (p)ercentage from 0 to 1.
If given an "x" value, we need to solve for which values of p fall between 0
& 1.
Once we find p, we go back and recalculate x & y.
One can do it a little better than this, but I tried to break the steps
down.  When solving for exact solutions, we need to be careful of Complex
Solutions, and eliminate them from consideration.

Needs["NumericalMath`SplineFit`"]

data={{0,0},{1,2},{-1,3},{0,1},{3,0}};

sf = SplineFit[data, Cubic];

ParametricPlot[sf[t], {t, 0, 4}, PlotRange -> All, Epilog ->
{AbsolutePointSize[5], Point /@ data}];

Let's find Y values given an X value.  As you can see from the above plot,
there may be more than one solution.

FindYs[sf_, x_] := Module[
    {equ, n, m, t},
    equ = Map[Tr[#*{1, p, p^2, p^3} ] &, sf[[4]], {2} ];
    n = Length[equ];
    m = Map[p /. NSolve[# == x, p] &, equ[[All, 1]]];
    m = Map[Chop, m];
    m = DeleteCases[m, _Complex, 2];
    t = Table[Select[m[[j]], 0 ? # ? 1 &], {j, n}];
    t = Flatten[t + Range[0, n - 1]];
    Map[sf, t][[All, 2]]
    ]


FindYs[sf,.5]

{0.5308262763331024,2.5446163293838877,0.6782327706023245}

FindYs[sf,1.6]

{0.27138844421503144}

The t + Range[0, n - 1] part may be confusing.  Once we find a fractional
value such as 0.7, we need to add an integer part to this value.  The
integer part is its location. (Zero based, so the first one is 0.)  For
example, when Plotting 0.5, the 0 means to use the "first" equation.

-- 
HTH   :>)
Dana DeLouis
Windows XP & Mathematica 5.2
(& waiting for 6.0)


"Ivan" <darknails at gmail.com> wrote in message
news:esola2$ef5$1 at smc.vnet.net...
> 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.
> 
> regards,
> 
>



  • Prev by Date: Re: "Transparency" with respect to differentiation
  • Next by Date: Re: poor efficiency of Numerical Integration at 5.2.0 ?
  • Previous by thread: Re: Evaluate a spline function
  • Next by thread: Re: Evaluate a spline function