NBM Dif Sim Comparedif
NBM Dif Sim Comparedif
NBM Dif Sim Comparedif
Introduction
This worksheet demonstrates the use of Mathematica to to compare the approximation of first order derivatives using three
different methods. Each method uses a point h ahead, behind or both of the given value of x at which the first derivative of f(x) is
to be found.
f ' HxL @
f Hx+hL- f HxL
Forward Difference Approximation (FDD)
h
Backward Difference Approximation (BDD)
f ' HxL @
f HxL- f Hx-hL
h
f ' HxL @
Central Difference Approximation (CDD)
f Hx+hL- f Hx-hL
2h
Section 1: Input
The following simulation approximates the first derivative of a function using different methods of approximation (FDD,BDD,-
CDD). The user inputs are
a) function, f(x)
b) point at which the derivative is to be found, xv
c) starting step size, h
d) number of times user wants to halve the starting step size, n
Function f(x):
xv = 4.0;
2 nbm_dif_sim_comparedif.nb
h = 0.2;
n = 12.0;
This is the end of the user section. All the information must be entered before proceeding to the next section.
Section 2: Procedure
The following procedure estimates the solution of first derivate of an equation at a point xv using different methods of approxima-
tion.
f (x) = function
xv = value at which the solution is desired
h = step size value
n = number of times step size is halved
derivD
derivD
derivD
Section 3: Calculation
f '@x_D
2 x_
+2 2 x_
x_
Ev = N@f '@xvDD
26 828.6
nbm_dif_sim_comparedif.nb 3
The loop halves the value of the step size n times. Each time, the approximate values of the first derivative are calculated and
saved in different vectors depending on the method of approximation. The approximate error is calculated after at least two
approximate values of the first derivative have been saved. The number of significant digits is calculated and written as the
lowest real number for each method. If the number of significant digits calculated is less than zero, then is shown as zero.
Section 4: Spreadsheet
The next table shows the step size value, exact value, approximate value, and the absolute relative true error as a function of the
step size value for each method of approximation.
Print@" ", "h", " ", "AvFDD", " ", "etFDD",
" ", "AvBDD", " ", "etBDD", " ", "AvCDD", " ", "etCDD"D;
Section 5: Graphs
The following graphs show the approximate solution, absolute relative true error and absolute relative approximate error as a
function of step size.
27 400
27 200
Step Size
0.02 0.04 0.06 0.08 0.10 0.12
26 800
FDD
26 600
BDD
26 400
CDD
Step Size
0.02 0.04 0.06 0.08 0.10 0.12
6 CDD
Step Size
0.02 0.04 0.06 0.08 0.10
References
Questions
2. Look at the true error vs. step size data for problem # 1. Do you see a relationship between the value of the true error and step
size ? Is this concidential? Is it similar for Forward and Backward Divided Difference? Is it different for Central Divided Differ-
ence method?
Conclusions
The worksheet shows the nature of accuracy of the three different methods of finding the first derivative of a continuous function.
Forward and Backward Divided Difference methods exhibit similar accuraciees as they are first order accurate, while central
divided difference shows more accuracy as it is second order accurate.
Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for
any errors contained within and are not liable for any damages resulting from the use of this material. This application is
intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application for-profit
activities.