Re: Problem with spline function object in Mathematica 6

• To: mathgroup at smc.vnet.net
• Subject: [mg95854] Re: Problem with spline function object in Mathematica 6
• From: jonm at wolfram.co.uk
• Date: Wed, 28 Jan 2009 06:43:26 -0500 (EST)
• References: <gletej\$4mm\$1@smc.vnet.net> <glmsp4\$mf8\$1@smc.vnet.net>

```To get the smoothness of derivative that the poster wants, Mathematica
7 provides a spline option to interpolation...

f=Interpolation[SplineTable, Method -> "Spline"];
Plot[f'[x],{x,0,64}]

On Jan 27, 11:56 am, dh <d... at metrohm.com> wrote:
> Hi,
>
> using splines in a 1dim context seems like an overkill.
>
> Use e.g. Interpolation:
>
> f=Interpolation[SplineTable];
>
> The derivative is simply:
>
> f'. E,g,:
>
> Plot[f'[x],{x,0,64}]
>
> hope this helps, Daniel
>
> bori... at sas.upenn.edu wrote:
> > Hello,
>
> > Here is a description of what I am trying to do. I have a tabulated
> > monotonically increasing function (imagine mass contained in concentric=
balls
> > with increasing radius). I need to obtain an interpolating function whi=
ch
> > preserves the monotonicity. I also need the derivative of the original =
function
> > - the density (and it needs to be positive everywhere). For that I use =
spline as
> > polynomial interpolations do not satisfy these requirements. I was able=
to
> > obtain the derivative of the spline object via a method described befor=
e on
> > MathGroup. As I need the density as a function of distance and the spli=
ne
> > function object is a parametric object in the end I need the inverse fu=
nctions
> > which give me the parameter in terms of the distance. The current probl=
em I
> > have is that the spline object is only correctly evaluated if the argum=
ent is a
> > number. If it is a symbol it automatically evaluates to the same symbol=
. I am
> > providing an arbitrary table for the original function.
>
> > Here is my current code:
> > SplineTable={{0,0},{1,1},{2,8},{3,27},{4,64}};
> > Spl=SplineFit[SplineTable,Cubic];
> > derivSpline=ReplacePart[Spl,Map[Append[Rest[#]*{1,2,3},0]&,Spl[[4]],{=
2}],4];
> > dMdr[x_]:=Last[derivSpline[x]]/First[derivSpline[x]];
> > drdt[x_] := First[derivSpline[x]];
> > sol3 = NDSolve[{param[0]==0,(param'[x]-(1/drdt[param[x]]))==0=
},param,{x,0,4}]
>
> > So again the problem I have is that drdt[param[x]] evaluates to param[x=
]
> > automatically (and immediately gives a division by 0 error in NDSolve) =
> > of attempting to evaluate param[x] to a number first.
> > The same happens with dMdr[x]. My goal in the end will be to evaluate
> > dMdr[param[x]] correctly when supplied with x.
>
> > I would also appreciate to know if there is an easier way to get the de=
rivative
> > in terms of distance from the original table while satisfying the physi=
cal
> > requirements.
> > Thanks in advance: Alexander Borisov.

```

• Prev by Date: Re: Re: Destructuring arguments to pure functions?
• Next by Date: Re: specifying the integration interval using a function
• Previous by thread: Re: Problem with spline function object in Mathematica 6
• Next by thread: Re: Dynamic, UpdateInterval and global variable