Title: Finding Roots of Nonlinear Equations
1 Finding Roots of Nonlinear Equations
2Sketch the Function
The best way to make an initial guess of the root
of the function f (x) is to sketch the function
x vs. f (x). The roots of the equation are the
points where the graph of y f (x) cuts the x-
axis. For example consider the equation f (x)
x3 2.5x2 2.46x 3.96 0
Lets try to plot this function. It is
just a one line code in MATLAB
x-40.14 plot(x,x.3-2.5x.2-2.46x3.96)
grid on ylim(-20 20)
3Tabulating the Function
It also helps to tabulate the function
So there are roots between
Read xmin, xmax,h X ? xmin While x xmax do
begin y ? f
(x) write x, y
x ?x h end Stop
Pseudo code to tabulate f (x)
Try to write this in MATLAB!
4Method of Successive Bisection
- Basis of Bisection Method
Theorem
An equation f(x)0, where f(x) is a real
continuous function, has at least one root
between xl and xu if f(xl) f(xu) lt 0.
5Bisection Method-cont.
Theorem
If function f(x) in f(x)0 does not change sign
between two points, roots may still exist between
the two points.
6Bisection Method-cont.
Theorem
If the function f(x) in f(x)0 does not change
sign between two points, there may not be any
roots between the two points.
7Bisection Method-cont.
Theorem
If the function f(x) in f(x)0 changes sign
between two points, more than one root may exist
between the two points.
8Algorithm for Bisection Method-1
Choose xl and xu as two guesses for the root
such that f(xl) f(xu) lt 0, or in other words,
f(x) changes sign between xl and xu.
9Algorithm for Bisection Method-2
Estimate the root, xm of the equation f (x) 0
as the mid-point between xl and xu as
10Algorithm for Bisection Method-3
Essentially this is what we need to do Check if
solution lies between a and b F(a)F(b) lt 0
? Try the midpoint m compute F(m) If F(m) lt
tol select m as your approximate solution
Otherwise, if F(m) is of opposite sign to F(a)
that is ifF(a)F(m) lt 0, then b m. Else a m.
Now check the following If f(xl) f(xm) lt 0,
then the root lies between xl and xm then xl
xl xu xm. If f(xl ) f(xm) gt 0, then the
root lies between xm and xu then xl xm xu
xu. If f(xl) f(xm) 0 then the root is xm.
Stop the algorithm if this is true.
xl and xu
11Algorithm for Bisection Method-3
Tolerance
So this is what we need to check
New estimate
Yes
Stop
Check if absolute relative approximate error is
less than pre-specified tolerance (tol) or if
maximum number of iterations is reached.
Absolute Relative Approximate Error
Using the new upper and lower guesses
No
12Bisection Method-Example
- Thermistors are temperature-measuring devices
based on the principle that the thermistor
material exhibits a change in electrical
resistance with a change in temperature. By
measuring the resistance of the thermistor
material, one can then determine the temperature.
13Example-cont.
- For a 10K3A Betatherm thermistor, the
relationship between the resistance R of the
thermistor and the temperature is given by
where note that T is in Kelvin and R is in ohms.
14Example-cont.
- For the thermistor, error of no more than 0.01o
C is acceptable. To find the range of the
resistance that is within this acceptable limit
at 19o C, we need to solve -
- and
- Use the bisection method of finding roots of
equations to find the resistance R at 18.99o C.
Conduct three iterations to estimate the root of
the above equation.
15Solution-Dry Run
Graph of function f(x)
16Solution-cont.
Choose the bracket
17Solution-cont.
First iteration..
18Solution-cont.
Second iteration..
19Solution-cont.
Third iteration..
20Solution-cont.
Testing Convergence
Table 1 Root of f(R)0 as function of number of
iterations for bisection method.
Thats the root
21Advantages and Drawbacks of Bisection Method
Advantages
- Always Convergent
- We can predict in advance the number of
iterations required for
desired accuracy
Drawbacks
If a function f(x) is such that it just touches
the x-axis it will be unable to find the lower
and upper guesses
- Function changes sign but root does not exist
If one of the initial guesses is close to the
root, the convergence is slower
22Read x0, x1, tol y0? f(x0) y1?f(x1) i? 0 If
(sign(y0) sign(y1) ) then begin
write starting values unsuitable
write x0, x1, y0, y1
stop end while (x1 x0 )/x1 gt
tol begin x2 ?
(x0 x1)/2 y2 ? f (x2)
i ? I 1
if ( sign (y0) sign(y2) ) then x0 ? x2 else
x1 ? x2 write solution converges to a
root write number of iterations is i write
x2, y2 stop
Bisection Method-Pseudo Code
23Improvement to Bisection Method
- Regula Falsi, or Method of False Position.
- Use the shape of the curve as a cue
- Use a straight line between y values to select
interior point - As curve segments become small, this closely
approximates the root
24Regula Falsi Method
curve
approximation
25Regula Falsi Method-cont.
adjacent1adjacent2
similartriangles
26Regula Falsi Method-cont.
- Pro as the interval becomes small, the interior
point generally becomes much closer to root - Con 1 if fa and fb become too close overflow
errors can occur - Con 2 cant predict number of iterations to
reach a give precision - Con 3 can be less precise than bisection no
strict precision guarantee - Con 4 slow convergence
27Regula Falsi Method-cont.
fa
a
b
fb
Problem with Regula Falsi -- if the graph is
convex down, the interpolated point will
repeatedly appear in the larger segment.
28Regula Falsi Method-cont.
Therefore a problem arises if we use the size of
the current interval as a criterion that the
root is found
fb
fx
a
b
x
If we use the criterion abs(fx) lt e, this is not
a problem. But this criterion cant be always
used (e.g. if function is very steep close to the
root)
There is a modified version of this method too
but we need not discuss that!
fa
29Regula Falsi-Pseudo Code
?
30Newton-Raphsons Method
31Newton-Raphsons Method-cont.
32Algorithm for Newton-Raphson Method
Calculate the next estimate of the root
Find the absolute relative approximate error
33Algorithm for Newton-Raphson Method-cont.
- Find if the absolute relative approximate error
is - greater than the pre-specified relative error
tolerance. - If so, go back to step 2, else stop the
algorithm. - Also check if the number of iterations has
exceeded - the maximum number of iterations.
34Example
Again consider the Thermistors example
To find the range of the resistance that is
within this acceptable limit at 190 C, we need to
solve the two equations below
and
35Solution-Dry Run
Graph of function f(x)
36Solution-cont.
First iteration
37Solution-cont.
Second iteration
38Solution-cont.
Third iteration
39Advantages and Drawbacks of Newton-Raphsons Method
Advantages
Converges fast, if it converges and requires only
one guess
Drawbacks
Inflection point
40Drawbacks cont.
Division by zero
41Drawbacks cont.
Root Jumping
42Drawbacks cont.
Oscillations near Local Maxima or Minima
43Newton Raphsons Method-Pseudo Code
Next lecture Secant Method, and some other
methods