Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ND's implementation is slow

19 views
Skip to first unread message

Andrew Moylan

unread,
Oct 16, 2007, 3:40:43 AM10/16/07
to
NumericalCalculus`ND uses Richardson extrapolation to estimate the
derivative, so e.g. ND[Sin[x], x, 5] has the following equivalent one-line
implementation in Mathematica:

InterpolatingPolynomial[{#, (Sin[5. + #] -
Sin[5.]) / #} & /@ (2.^-Range[0, 6]), 0]
>> 0.2836621854529269

Compare with:

Needs["NumericalCalculus`"]
ND[Sin[x], x, 5]
>> 0.2836621854529268

Interestingly, the one-line implementation in Mathematica is quite a bit
faster than ND! :

Do[
InterpolatingPolynomial[{#, (Sin[5. + #] -
Sin[5.]) / #} & /@ (2.^-Range[0, 6]), 0]
,
{10000}
] // Timing
>> {1.392, Null}

Do[ND[Sin[x], x, 5], {10000}] // Timing
>> {7.561, Null}

Part of this is due to extra overheads for ND like processing user input and
options. Even taking this into account, however, the
InterpolatingPolynomial-based implementation above is still about twice as
fast. I've modfied my NDerivative package to use this method instead of
NumericalCalculus`ND and I've also added a drop-in replacement for ND,
called FastND.

Do[FastND[Sin[x], x, 5], {10000}] // Timing
>> {4.046, Null}

If you want to use NDerivative or FastND, you can get them from
http://andrew.j.moylan.googlepages.com/mathematica.


0 new messages