Escolar Documentos
Profissional Documentos
Cultura Documentos
f (x) = lim
f (x + h) f (x) h
(1)
Numerical differntiation becomes important as a result of the increased reliance on computers to solve problems. For example, if a function exists only as tabulated values at discrete intervals along the abscissa, the derivatives of the function must be calculated numerically. Since derivatives of a function exist only as limiting values, such as that given by Eq. (1), it is usually impossible in numerical work to deal with them directly. Instead we use finite differences, meaning small differences in the function at nearby points. A straightforward generalization of Eq. (1) is to make use of the difference
f (x) = f (x + h) f (x)
and equate f (x) as the quotient f (x)/h for finite h . The quantity f (x) is known as the forward difference of the function f (x) at x . This is not the only way to define the value of the difference of a function at two adjacent points. For example, we could have used the backward difference
f (x ) =
f (x + h ) f (x h) 2h
whose truncation error is on the order of h2 . Another widely employed extrpolated difference form is
f (x) =
One can even use the "5-point" formula
f (x ) =
Formulas for higher derivatives can be constructed as
f (x) =
f (x + h) 2f (x) + f (x h) h2
The 5-point difference formula for the second derivative of f(x) that are accurate to a higher order in h can be derived straightforwardly :
f (x) =
Exercises 1. Implement various formulae given in the text above. 2. Change f(x) and see how the performance varies. 3. Change float to double and observe how the performance changes. * Default precision for REAL numbers is 32 bit (at least for Intel PC with Visual Studio), which has 7 significant digits and is called SINGLE PRECISION, while DOUBLE PRECISION numbers use 64-bits and have 15 significanr digits. Below is a double precision version of the program. Function tested is 1/x.