Anda di halaman 1dari 12

Numerical Differentiation UC Berkeley Fall 2004, E77

http://jagger.me.berkeley.edu/~pack/e77

Copyright 2005, Andy Packard. This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Differentiation
For a function f, the derivative of f at x is defined as the limit

The derivative of f at x is the slope of the graph of the function at x.

Numerical Differentiation
A common manner to numerically estimate of the derivative is a finite-difference of the quotient
No limit, just a fixed, nonzero h

The forward difference at x with stepsize h (h>0) is

The backward difference at x with stepsize h (h>0) is

The centered difference at x with stepsize h (h>0) is

Numerical Differentiation
If the function values are only available as data pairs

With each yi = f(xi), then the finite differences are computed with the data (assuming the xi are sorted)

What are we actually computing?


Average values: If g is integrable, then the average value of g over the interval [a,b] is defined as

In other words,

is the constant which satisfies


ie., the only constant function which has the same integral over [a,b] as does g is the constant function whose value is

What are we actually computing? If f is differentiable, then

If ab, then

Average value of f over the interval (a,b)

What are we computing? (contd)


Mean-Value Theorem: If f is
differentiable on (a,b) continuous on [a,b]

then there is an y(a,b) such that

What are we computing? (contd)


This gives two interpretations of the finite-difference

Average value of f over the interval (a,b)

exact value of f at some point in interval (a,b)

What are we computing? (contd)


So, two interpretations of the finite-difference

Average value of f over the interval (x,x+h)

Bounding the Errors


The second derivative of f gives how quickly the first derivative is changing. Bound the error between the finite difference estimate and the actual derivative using
finite difference is the exact answer for some intermediate value intermediate first-derivative values differ because of 2nd derivative. use Taylor series to bound the error as

Error between finite difference and actual derivative

Higher Order derivatives


Use the finite difference estimates of the 1st derivative to compute the 2nd derivative, based on

Example: Use backward formula, with forward derivatives

Matlab functions
Theres not much in the way of functions for numerical differentiation. Essentially, you employ the expressions we introduced today. If X is a row vector, then

diff(X) returns
[X(2)-X(1) X(3)-X(2) X(end)-X(end-1)] Given row vectors Xdata, Ydata (each 1-by-N)

Z = diff(Ydata)./diff(Xdata) Z is 1-by-(N-1). Element Z(i) is the forward derivative at X(i)

Anda mungkin juga menyukai