Re: Simple Question on Derivatives
- From: ellieandrogerxyzzy@xxxxxxxxxxxxxxxxxxxxxx (Roger Stafford)
- Date: Fri, 05 Aug 2005 21:46:37 GMT
In article <ef100ad.-1@xxxxxxxxxxxxxxxx>, "J Dagg"
<james.dagg@xxxxxxxxxxxx> wrote:
> Can I safely compute the second derivative of a function by using
> diff(y,2)./diff(x,2)? If not, what's the simplest way to do it?
-------------------
No James, all this gives you, at best, is the ratio between two second
derivatives, and moreover you haven't specified what variable you are
differentiating with respect to. If x and y are symbolic variables, and
you are differentiating with respect to x, you will be dividing by zero.
What you need is just the numerator with y being expressed explicitly in
terms of x.
If, on the other hand, x and y are discrete numerical arrays, it still
doesn't give you what you want. If the x values are evenly spaced, you
will again be dividing by zero. If x and y are both closely spaced in
accordance with some, possibly hypothetical, third variable which is
itself evenly spaced, then the formula you should use for the second
derivative of y with respect to x is:
(diff(x).*diff(y,2) - diff(y).*diff(x,2))./diff(x).^3
This comes from the famous chain rule in calculus. Bear in mind that even
this is only an approximation depending on how close the spacing is, not
to mention on the accuracy of the x and y values. The requirement that
the third variable be evenly spaced is essential in this case. Otherwise
second differences do not correspond to any kind of second derivative with
respect to anything.
This is one level of differentiation beyond the formula for a first
derivative of y with respect to x:
diff(y)./diff(x)
again if both x and y are spaced according to some closely spaced third
variable. In this case the requirement of even spacing for the third
variable can be relaxed to merely close spacing.
The point is that 'diff(x)' applied to a discrete array of numbers does
not by itself give a derivative for the numbers. It's only a first
difference. Similarly 'diff((),2)' is only a second difference and is
possibly even farther from being anything like a second derivative.
(Remove "xyzzy" and ".invalid" to send me email.)
Roger Stafford
.
- Follow-Ups:
- Re: Simple Question on Derivatives
- From: Roger Stafford
- Re: Simple Question on Derivatives
- References:
- Simple Question on Derivatives
- From: J Dagg
- Simple Question on Derivatives
- Prev by Date: Re: fzero and TolX in MATLAB 6.5
- Next by Date: Re: Log base e plot
- Previous by thread: Simple Question on Derivatives
- Next by thread: Re: Simple Question on Derivatives
- Index(es):
Relevant Pages
|
Loading