http://cpp.gantep.edu.tr
C++ resources. Faculty of Engineering, University of Gaziantep


MAIN  Tutorials  Howtos  nmPrimer  Misc  Links  Contacts  
Last modified: Sat, 31 Oct 2009 12:23:17 +0200
Complete: ################## (90%) Differentiation of a function f(x)
The derivative f'(x) of a function f(x) is simply the gradient of the function at a point x. Finding the derivative of a function analytically may be difficult and so a numerical solution may be necessary or simply convenient. The following sections describe two methods of differentiation, both are based on the approximation of the gradient of f(x) around a value x. 1. The Central Difference Approximation (CDA) In the figure below, the gradient of the function at x is approximated by the line drawn from xh to x+h. This is called the Central Difference Approximation (CDA). Intuitively this approximation looks right, and as h reduces in size the approximation should improve. Below the diagram is the proof from Taylor's expansion that the CDA does return the first derivative with an error of approximately h^{2}/6 f'''(x); i.e. the error is proportional h^{2}. The value of h should therefore be chosen to be small, however if it is too small then roundoff errors will dominate the total error. The choice of h may therefore require some experimentation.The CDA is implementated in the program below. nmprimerCDA.cpp: Central Difference Approximation (CDA) for the derivative of a function.
2. The Richardson Extrapolation Method The Richardson Extrapolation Approximation (REA) provides a higherorder approximation, i.e. the truncation error is proportional to a higher power of h and so is much smaller for h<<1. The truncation error in the REA is approximately h^{4}/30 f`````(x). You can prove this by constructing the REA using Taylor's expansion as performed above for the CDA.The REA is implementated in the program below. nmprimerREA.cpp: The Richardson Extrapolation Method for the derivative of a function.
Complete: ################## (90%) 