MathGroup Archive 2009

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

Search the Archive

Interpolation with Method->Spline

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98000] Interpolation with Method->Spline
  • From: John_V <jvillar.john at gmail.com>
  • Date: Fri, 27 Mar 2009 05:37:52 -0500 (EST)

I upgraded to Mathematica 7.01 today so I could try the new Method->Spline
option of the Interpolation function. I've experimented with it, and it
appears to give the natural spline (second derivative = 0 at the data
endpoints). I would like to specify the *first *derivative at the endpoints.
It is possible to do this for splines outside of Mathematica (e.g.,
Numerical Recipes describes it), and Mathematica permits it for ordinary
polynomial interpolation, so I tried using the same syntax. Here's an
example:

In[53]:= exampData = {{{0.}, 0., 0.}, {{0.5}, 0.00042},
     {{1.}, 0.0013}, {{1.5}, 0.00614}, {{2.}, 0.026},
     {{2.2}, 0.0622}, {{2.4}, 0.153}, {{2.6}, 0.188}}

Out[53]= {{{0.}, 0., 0.}, {{0.5}, 0.00042}, {{1.}, 0.0013},

  {{1.5}, 0.00614}, {{2.}, 0.026}, {{2.2}, 0.0622},

  {{2.4}, 0.153}, {{2.6}, 0.188}}

Notice that the first data input has an extra 0 after the function value to
specify a 0 first derivative at x=0. This works for polynomial
interpolation. However, for spline interpolation:

In[54]:= f = Interpolation[exampData, Method -> "Spline"]

Out[54]= InterpolatingFunction[]

If you plot this (e.g., Plot[f[x], {x, 0, 1}] ) you'll see that f clearly
has a negative slope at x=0.

In[56]:= f[0.1]

Out[56]= -0.0000687322

Unfortunately for me, f represents a physical quantity for which negative
values are impossible (and cause mischief in later calculations). This was
why I was trying to specify the 0 derivative at x=0: in hopes of making the
spline behave itself near the endpoint so I could enjoy its other nice
properties (minimum curvature) elsewhere.

This is a new and not-yet-well-documented feature, so maybe there's a syntax
or a workaround to do what I want. Does anyone know of one?

John



  • Prev by Date: Re: HoldAll for Integrate
  • Next by Date: Re: What's going on here (Table-generated lists)?
  • Previous by thread: Re: pdf export problem
  • Next by thread: Re: Interpolation with Method->Spline