Environmental Engineering Reference
In-Depth Information
where f 0 ðxÞ
denotes the derivative. It can be shown easily that the new x is the
position where the tangent on the function graph at the old x position meets
the x -axis.
The iteration stops, if the change of approximation within the last iteration
is lower than a specified tolerance (1), or if the maximum number of iterations
is reached (2). The following command sequence demonstrates the method by
calculating the zero of the cosinus, i.e.
p
/2.
The complete code is included in the accompanying software under the
name 'newtondemo.m'.
In the first three lines tolerance, maximum number of iterations and initial
guess are specified. What follows is the initialization of the error variable
err and the iteration counter nit . In the while -loop the new x-position is
calculated from the old one. First, the iteration counter is increased. Then,
after function and derivative are evaluated, the change of x (the second term
in the iteration formula) is computed by the command dx ¼ F/DF . The
absolute value of dx becomes the error variable err . Finally, the new x is
calculated.
The result of the iteration for the cosinus as demonstration function is
x ¼
1.5708, which is already reached after three iterations. There are further
iterations, because the required tolerance with 10 7 is higher than the digits
presented in the MATLAB
command window.
Note that the Newton method requires an explicit formula for the deriva-
tive of the function.
®
Search WWH ::




Custom Search