How to use a root solver

advertisement
Last Rev.: 17 JUL 08
ROOT SOLVERS : MIME 3470
ROOT SOLVERS
f( x)  cos( x)  x
~~~~~~~~~~~~~~
Here we want to find the point(s) where a function is zero; i.e., where it
crosses the abscissa. These points are called roots. The root solver
used in Mathcad may not use the Newton-Raphson method described
below; but, such is more that adequate to describe the overall problem.
Newton’s Method [Wiki]: In numerical analysis, Newton's
method (also known as the Newton–Raphson method, named after
Isaac Newton and Joseph Raphson) is perhaps the best known
method for finding successively better approximations to the zeros
(or roots) of a real-valued function. Newton's method can often
converge remarkably quickly, especially if the iteration begins
“sufficiently near” the desired root. Just how near “sufficiently near”
needs to be, and just how quickly “remarkably quickly” can be,
depends on the problem. Unfortunately, far from the desired root,
Newton's method can easily lead an unwary user astray with little
warning. Thus, good implementations of the method embed it in a
routine that also detects and perhaps overcomes possible
convergence failures.
Newton's method can also be used to find a minimum or
maximum of such a function, by finding a zero in the function's first
derivative.
Explanation by Example
Find the positive number x where cos(x) = x3. We can rephrase
this as finding the zero of f(x) = cos(x) − x3. In studying any
function, it is best to first plot it and see what it looks like.
f( x)  cos( x)  x
3
Page 1
1000
For x =
x0  0.5
As a check:
m  x0  b  0.7525826
Then find x1 such that f(x1) = 0
x1  1.11214169306
0
5
10
x0
x1
0
m x b
5
10
0
0.5
1
1.5
2
x
In computing x1, we actually used the relation x1  x0 
f  x0 
f  x0 
,
where f x0  is represented above as df(x). Using this for successive
approximations of the root we can converge on a solution for our root.
x5  x4 
x
From this plot, it “appears” that the root (zero-crossing) is near
x = 0; however, it is shown in the Mathcad object just above that
f(0) = 1. So, just where does the function cross the x-axis?
The method of solution is as follows: one starts with an initial
guess which is reasonably close to the true root, then the function is
approximated by its tangent line, and one computes the x-intercept of
this tangent line. This x-intercept will typically be a better approximation to the function’s root than the original guess and the
method can be successively iterated for better and better solutions.
As cos(x) ≤ 1 for all x and x3 > 1 for x > 1, we know that our zero
(root) lies between 0 and 1. We try a starting value of x0 = 0.5.
 12
0
f( x)
x4  x3 
5
m  x1  b  5.5191407  10
5
x3  x2 
10
m  1.2294255
b  1.3672954
f( x)
2000
 
m  df x0
x2  x1 
1000
2
df( x)  sin ( x)  3  x
the slope of the function is
And, the x-intercept of
the tangent line through
x0 is
0
0
f( 0.5 )  0.7525826
The derivative of f(x) is:
x1  x0 
f( 0 )  1
3
x6  x5 
 
 
f x1 
df x1 
f x2 
df x2 
f x3 
df x3 
f x4 
df x4 
f x5 
df x5 
f x0
df x0
x1  1.1121416
x2  0.9096727
x3  0.8672638
x4  0.8654771
x5  0.8654740
x6  0.8654740
Mathcad produces the same results by using the root function as
shown below.
x  root( f( x)  x  0  1)
x  0.8654740
Here the arguments of the argument list for the function are:
f(x) – the function for which one is seeking a root
x – the actual variable for which the root is sought
0, 1 – the range over which one is seeking a root
The range arguments are very important as some functions (as
shown below) have many roots and the iterative procedure may
determine a root that was not desired. This is another reason to
first plot the function for which the root is desired.
 2
g ( x)  sin ( x)  cos x 
2
g ( x)
0
0
2
10
5
0
x
5
10
Download