[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: diff(x) question
From: |
George White |
Subject: |
RE: diff(x) question |
Date: |
Tue, 19 Jan 1999 19:37:05 -0400 (AST) |
On Tue, 19 Jan 1999, Van den Eynde Gert wrote:
> > Diff computes forward differences. Not the derivative. If you want to
> > approximate the derivative by using forward differences you have to
> > divide by the step h with which you make your function discrete.
> > In this case h = .1
> >
> >
> > df f(t+h) - f(t)
> > -- (t) =~ --------------- + O(h)
> > dt h
> >
>
> just want to update my previous answer.
>
> I suggest to use a symmetrical formula
>
> (f(t+h) - f(t-h))/(2h)
>
> this gives an error of O(h^2) AND you can use Richardson extrapolation
> (extrapolation to the limit). IMHO, this is a good way to compute a
> numerical derivative.
>
> Gert Van den Eynde
Neither of the above is appropriate for machine arithmetic. For
example, the first formula above should replace "h" with "h2" as follows:
tmp=t;t = t+h;h2 = t-tmp;t = tmp;
This is necessary since t+h will not, in general, be representable in
machine arithmetic. The assignment of t to tmp is intended to remind the
reader that optimizing compilers may simplify away the necessary
distinction. What does octave do with:
h2=(t+h)-t;
and will future version do the same?
--
George White <address@hidden> Halifax, Nova Scotia