Problem with spline function object in Mathematica 6

• To: mathgroup at smc.vnet.net
• Subject: [mg95663] Problem with spline function object in Mathematica 6
• From: borisov at sas.upenn.edu
• Date: Sat, 24 Jan 2009 06:19:12 -0500 (EST)

```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.