Re: Re: Re: Finding derivatives of a list?
- To: mathgroup at smc.vnet.net
- Subject: [mg40926] Re: [mg40888] Re: [mg40854] Re: [mg40816] Finding derivatives of a list?
- From: Bobby Treat <drmajorbob+MathGroup3528 at mailblocks.com>
- Date: Thu, 24 Apr 2003 05:29:28 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On the other hand, mean absolute relative error in Runge's example is
around 5% for InterpolationOrder -> 7.
Needs["Graphics`Colors`"]
mean=Tr[#]/Length[#]&;
runge[x_] := 1/(1 + 20 x^2);
Plot[runge[x], {x, -1, 1}, Frame->True,
PlotLabel->"Runge's example"];
pts = Table[{x, runge[x]}, {x, -1., 1, 0.1}];
interp = Interpolation[pts, InterpolationOrder -> 7];
Plot[{runge''[x], interp''[x]}, {x, -1, 1},
Frame -> True, PlotLabel ->
"second derivative", PlotStyle -> {Red, Blue}];
Round[100mean@Table[ Abs[1 -
interp''[x]/runge''[x]],
{x, -1., 1, 0.05}]]"% Mean Relative Absolute Error"
5 "% Mean Relative Absolute Error"
I used the sampled points and midpoints between them for the mean.
Here's a measure of mean absolute error on the interval:
Needs["NumericalMath`NIntegrateInterpolatingFunct`"]
g = Interpolation@Last@Cases[plot, Line[a_] :> a, Infinity];
NIntegrateInterpolatingFunction[Abs[runge''[x] - g@x], {x, -1, 1}]/2
0.422366
So -- differentiating data is an iffy proposition at best, but if you
MUST make a stab at it, interpolation is a start. If there's no
"correct" function to compare answers with, the interpolated second
derivative could be EXACTLY right, for all we know.
But if you know the functional form, by all means differentiate it!
Bobby
-----Original Message-----
From: Selwyn Hollis <selwynh at earthlink.net>
To: mathgroup at smc.vnet.net
Subject: [mg40926] [mg40888] Re: [mg40854] Re: [mg40816] Finding derivatives of
a list?
I feel compelled to point out that using interpolation for this purpose
is, in general, a Bad Idea.
Please have a look at the following, which uses an example attributed
to Runge. The Do loop plots the difference between f''[x] and the
second derivative of the InterpolatingFunction based on 21 nodes -1,
-.9, ..., .9, 1, for InterpolationOrders 3 through 20. You'll notice
that the difference is quite large in all cases.
runge[x_] := 1/(1 + 20 x^2);
Plot[runge[x], {x, -1, 1}, Frame->True, PlotLabel->"Runge's example"];
pts = Table[{x, runge[x]}, {x, -1., 1, 0.1}];
Do[ interp = Interpolation[pts, InterpolationOrder -> n];
Plot[Evaluate[{runge''[x] - interp''[x]}], {x, -1, 1},
PlotRange -> {-10, 10},
PlotLabel -> "InterpolationOrder --> " <> ToString[n]],
{n, 3, 20}]
-----
Selwyn Hollis
http://www.math.armstrong.edu/faculty/hollis
On Tuesday, April 22, 2003, at 06:44 AM, Daniel Lichtblau wrote:
> AES/newspost wrote:
>>
>> Specific problem is how to generate a list of values of the second
>> derivative of a relatively smooth function at a set of equally spaced
>> points, when the function itself is known only as a list of numerical
>> values at those same points?
>>
>> --
>> "Power tends to corrupt. Absolute power corrupts absolutely."
>> Lord Acton (1834-1902)
>> "Dependence on advertising tends to corrupt. Total dependence on
>> advertising corrupts totally." (today's equivalent)
>
> Here are some possibilities.
>
> (i) Form an interpolation of relatively high order (say 6 or so). Take
> second derivatives.
>
> (ii) Use finite differences to approximate the second derivatives.
>
> (iii) Use Fourier to get the approximated derivatives. See for example
>
> Wang, Jing. B (2002). Numerical differentiation using Fourier. The
> Mathematica Journal 8:3. 383-388.
>
> I believe there was a small error in the code provided; you might want
> to contact the author at wang at physics.uwa.edu.au
>
>
> Daniel Lichtblau
> Wolfram Research
>
>