MathGroup Archive 2009

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

Search the Archive

Re: Re: Interpolation with Method->Spline

  • To: mathgroup at
  • Subject: [mg98093] Re: [mg98024] Re: Interpolation with Method->Spline
  • From: John_V <jvillar.john at>
  • Date: Mon, 30 Mar 2009 04:41:49 -0500 (EST)
  • References: <gqia9h$oo8$> <>

Setting all first derivatives is not a requirement for *ordinary *interpolation.
That is, if you use the example data that I gave, but leave out the
Method->Spline, you get a polynomial interpolation with 0 derivative at the
first endpoint, just as you'd expect. It is only with Spline that it seems
not to work.

It wouldn't make sense to require all derivatives to be specified. (This
would render the interpolation less useful since we often don't know what
the derivatives ought to be, and in such cases we'd like to leave the
interpolation free to optimize other properties.) The problem of fitting a
spline through points in an interval is ambiguous to the extent of two
boundary conditions, one at each end of the interval. A frequent choice is
to arbitrarily require the curvature at the endpoints to be 0--but another
common choice is to specify some other derivative there, which is what I'd
like to do.

On Sat, Mar 28, 2009 at 6:42 AM, < at> wrote:
> You have to set the first derivative value for ALL points in your
> series. In other case Mathematica will ignor the third number for
> first point.
> I add random numbers as third element for your points (and reevaluate
> interpolation each time after addition) and the interpolated data
> curve was changed only when I set all points with derivative value.
> All data must be with derivative or all without it.

John_V had written

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

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?


  • Prev by Date: Re: Histograms and Iterators - Beginner Question
  • Next by Date: Re: extracting points and projecting
  • Previous by thread: Re: Interpolation with Method->Spline
  • Next by thread: Does mathematica7 support fontconfig?