Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MATHEMATICA: Cubic Spline Interpolation

302 views
Skip to first unread message

Rajesh Pendekanti (ERC ndd)

unread,
Dec 20, 1994, 1:15:05 PM12/20/94
to


Hi!


I am looking for the Cubic Spline Interpolation in Mathematica.

ie given array {{x1,y1},{x2,y2},....,{xn,yn}}
with x1<x2< .... <xn

I need to be able to obtain the value of 'y' at
any 'x' ( x1<x<xn ).

Is there a pre-defined Mathematica function call for this??

Also is there a ftp / mosaic site with useful Mathematica
programs????

Thanks

Rajesh


Louis Gascoigne

unread,
Dec 20, 1994, 5:10:46 PM12/20/94
to
r...@sunbar.mc.duke.edu (Rajesh Pendekanti (ERC ndd)) writes:

>ie given array {{x1,y1},{x2,y2},....,{xn,yn}}
>with x1<x2< .... <xn

>I need to be able to obtain the value of 'y' at
>any 'x' ( x1<x<xn ).

>Is there a pre-defined Mathematica function call for this??

Why don't you just use a polynomial fit and then get a function in terms
of y?

Robert Knapp

unread,
Jan 3, 1995, 2:33:06 PM1/3/95
to

In article <eapu294....@taurus.oac.uci.edu>,
Louis Gascoigne <eap...@taurus.oac.uci.edu> wrote:

> Why don't you just use a polynomial fit and then get a function in terms
> of y?

The appropriateness of this depends on circumstances--in amny cases, using an
excessively high order polynomial can lead to highly oscillatory
approximations.

Sinan Karasu <si...@u.washington.edu> wrote:

> Why not use NumericalAnalysis`SplineFit.m
> (or something like that...)
>
> Sinan
>

Actually it is NumericalMath`SplineFit`


An alternative to using cubic splines is to use the Mathematica function
Interpolation. This command constructs an InterpolatingFunction which is a
LOCAL approximation (default cubic) based on data at the nearest points.
If you data contains error, this may be better than a spline which is not
simply a local approximation. The advantage of the spline is that it is
continuously differentiable. (The result of Interpolation can be made
continuously differentiable by specifying derivatives with the data--in
which case it uses Hermite Interpolation.)

Here is an example:

In[7]:=
data = Table[ {x, N[Sin[x]]},{x, 0, 10}];
In[8]:=
fun = Interpolation[ data ];
In[9]:=
fun[1.5]
Out[9]=
0.975987
In[10]:=
Plot[ fun[x], {x, 0, 10}];

or the spline:


In[18]:= Needs["NumericalMath`SplineFit`"]

In[19]:= sp = SplineFit[data,Cubic]

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

In[20]:= sp[1.5]

Out[20]= {1.5, 0.994193}


Robert Knapp
Wolfram Research, Inc.

Tel (217) 398-0700 Fax (217) 398-0747 rkn...@wri.com

0 new messages