Re: Problem with spline function object in Mathematica 6
- To: mathgroup at smc.vnet.net
- Subject: [mg95772] Re: Problem with spline function object in Mathematica 6
- From: dh <dh at metrohm.com>
- Date: Tue, 27 Jan 2009 06:56:26 -0500 (EST)
- References: <gletej$4mm$1@smc.vnet.net>
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
borisov 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 which
> 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 before on
> MathGroup. As I need the density as a function of distance and the spline
> function object is a parametric object in the end I need the inverse functions
> which give me the parameter in terms of the distance. The current problem I
> have is that the spline object is only correctly evaluated if the argument 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) instead
> 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 derivative
> in terms of distance from the original table while satisfying the physical
> requirements.
> Thanks in advance: Alexander Borisov.
>