       Re: Numerical derivative on non-uniform grid

• To: mathgroup at smc.vnet.net
• Subject: [mg30275] Re: [mg30257] Numerical derivative on non-uniform grid
• From: BobHanlon at aol.com
• Date: Sat, 4 Aug 2001 20:02:04 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```In a message dated 2001/8/4 1:44:15 AM, jim at freeze.org writes:

>Can Mathematica take a numerical derivative (on a list of x,y pairs)
>where the x spacing is non-uniform?
>

data = Table[ToExpression[{"x"<>ToString[k], "y"<>ToString[k]}], {k, 5}];

Rest[data-RotateRight[data]] /. {x_, y_} :> y/x

{(y2 - y1)/(x2 - x1),
(y3 - y2)/(x3 - x2),
(y4 - y3)/(x4 - x3),
(y5 - y4)/(x5 - x4)}

You can also use an interpolating function

data = ({#, Sin[#]}& /@ Sort[Table[2*Pi*Random[], {50}]]);

f = Interpolation[data];

Table[{x, f[x], f'[x]}, {x, Pi/8., 15Pi/8, Pi/8}]//TableForm

Plot[{f[x], f'[x]}, Evaluate[{x, f[[1, 1, 1]], f[[1, 1, 2]]}],
PlotStyle -> {RGBColor[0, 0, 1], RGBColor[1, 0, 0]}];

Bob Hanlon
Chantilly, VA  USA

```

• Prev by Date: Importing Graphics into Mathematica notebooks?
• Next by Date: Re: MathLink for Excel XP?
• Previous by thread: Numerical derivative on non-uniform grid
• Next by thread: Left Justifying PlotLabel?