Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

Numerical Methods Applied to Mechatronics

Lecture No 5
Escuela de Ingeniera Mecatrnica
Universidad Nacional de Trujillo
NON-LINEAR EQUATIONS ROOTS
Dr. Jorge A. Olortegui Yume, Ph.D.
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 2
ROOTS PROBLEMS
Function f can be written as:
f(x)=0
particular x satisfying equality is a root
These problems often occur when a design
problem presents an implicit equation for a
required parameter.
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 3
GRAPHICAL METHODS
Plot of the function and observe
where it crosses the x-axis.
Graphing can also indicate where
roots may be and where some root-
finding methods may fail:
a) Same sign, no roots
b) Different sign, one root
c) Same sign, two roots
d) Different sign, three roots
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 4
BRACKETING METHODS
Make 2 initial guesses that bracket the root
Brackets: 2 guesses x
l
and x
u
fulfilling f(x
l
) f(x
u
) < 0
[ ]
x
l
x
u
f(x
u
)
f(x
l
)
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 5
Incremental Search Methods
Disadvantages:
BRACKETING METHODS
If spacing are too far
apart, solutions may
be missed due to
capturing an even
number of roots
within two points.
Cannot find brackets
containing even-
multiplicity roots
Tests the value of function at evenly spaced intervals to
find brackets by function sign change.
Good Practice: Plot the function along with the algorithm
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 6
Incremental Search Methods
BRACKETING METHODS
Example: Matlab program
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 7
Incremental Search Methods
BRACKETING METHODS
Example: Matlab program(CONT)
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 8
The Bisection Method
BRACKETING METHODS
Incremental Search Methods
a variation of the incremental
search method the interval
is always divided in half.
If a function changes sign over
an interval, the function value
at the midpoint is evaluated.
The location of the root is then
determined as lying within the
subinterval where the sign
change occurs.
The absolute error is reduced
by a factor of 2 for each
iteration.
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 9
Bisection Method Errors
BRACKETING METHODS
Incremental Search Methods
The absolute error of the bisection method is solely
dependent on the absolute error at the start of the
process (the space between the two guesses) and the
number of iterations:
The required number of iterations to obtain a particular
absolute error can be calculated based on the initial
guesses:

E
a
n
=
Ax
0
2
n

n = log
2
Ax
0
E
a,d
|
\

|
.
|
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 10
BRACKETING METHODS
Incremental Search Methods
The Bisection Method
Example: Matlab program
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 11
BRACKETING METHODS
Incremental Search Methods
The Bisection Method
Example: Matlab program
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 12
BRACKETING METHODS
The False Position Method
It determines the next
guess not by splitting the
bracket in half but by
connecting the endpoints
with a straight line and
determining the location
of the intercept of the
straight line (x
r
).
The value of x
r
then
replaces whichever of the
two initial guesses yields
a function value with the
same sign as f(x
r
).

x
r
= x
u

f (x
u
)(x
l
x
u
)
f (x
l
) f (x
u
)
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 13
BRACKETING METHODS
Bisection vs False Position
Bisection does not take into
account the shape of the
function; this can be good
or bad depending on the
function!
Bad:

f (x) = x
10
1
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 14
BRACKETING METHODS
The False Position Method
Homework: Write a general purpose Matlab programfor the
False position method
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 15
OPEN METHODS
Open methods differ from bracketing methods, in
that open methods require:
1 starting value or
2 starting values (not necessarily bracketing a
root).
Open methods may diverge as the computation
progresses, but when they do converge, they
usually do so much faster than bracketing methods.
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 16
OPEN METHODS
GRAPHICAL COMPARISON OF METHODS
a) Bracketing method
b) Diverging open method
c) Converging open method
Note speed!
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 17
OPEN METHODS
SIMPLE FIXED-POINT METHOD
Rearrange f(x)=0 to the form
Use g(x) to predict a new value of x - that is,
Approximate error :

c
a
=
x
i+1
x
i
x
i+1
100%
( ) x g x =
( )
i i
x g x =
+1
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 18
OPEN METHODS
SIMPLE FIXED-POINT METHOD
Example: Solve for the roots of f(x)=e
-x
-x
Solution:
1. Rearrange
2. Start with a guess for x
0
. For this case x
0
=0
3. Use the iteration formula
4. Continue until some tolerance is reached
( ) x g x = x=e
-x
i x
i
g(x
i
)=e
-x
i
|c
a
| %
0 0.0000 1.0000
1 1.0000 0.3679 100.000
2 0.3679 0.6922 171.828
3 0.6922 0.5005 46.854
4 0.5005 0.6062 38.309
5 0.6062 0.5454 17.436
( )
i i
x g x =
+1

c
a
=
x
i+1
x
i
x
i+1
100%
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 19
OPEN METHODS
SIMPLE FIXED-POINT METHOD
Example: Solve for the roots of f(x)=e
-x
-x
Solution:
( ) x g x =
567143 . 0 = x
0
0
= x
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 20
OPEN METHODS
SIMPLE FIXED-POINT METHOD
Example: Solve for the roots of f(x)=e
-x
-x
Solution:
0
0
= x
( ) 1
0
= x g
( ) 1
0 1
= = x g x
( ) 3679 . 0
1
= x g
( ) 3679 . 0
1 2
= = x g x
( ) 6922 . 0
2
= x g
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 21
OPEN METHODS
SIMPLE FIXED-POINT METHOD
Convergence:
Requires :
a) Convergent, 0 g(x) <1
b) Convergent, -1< g(x) 0
c) Divergent, g(x) >1
d) Divergent, g(x) <-1
( ) 1 ' < x g
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 22
OPEN METHODS
SIMPLE FIXED-POINT METHOD
Convergence:
Requires :
a) Convergent, 0 g(x) <1
b) Convergent, -1< g(x) 0
c) Divergent, g(x) >1
d) Divergent, g(x) <-1
( ) 1 ' < x g
This does not guarantee
convergence
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 23
OPEN METHODS
NEWTON-RAPHSON METHOD
Based on forming the tangent line to the f(x) curve at
some guess x, then following the tangent line to where it
crosses the x-axis.

f
'
(x
i
) =
f (x
i
) 0
x
i
x
i+1
x
i+1
= x
i

f (x
i
)
f
'
(x
i
)
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 24
OPEN METHODS
NEWTON-RAPHSON METHOD
Pros and Cons
Pro: The error of the i+1
th
iteration is
roughly proportional to the square of
the error of the i
th
iteration - this is
called quadratic convergence
Con: Some functions show slow or
poor convergence
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 25
OPEN METHODS
NEWTON-RAPHSON METHOD
Matlab Code
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 26
OPEN METHODS
SECANT METHOD
Newton-Raphson method problem:
Evaluation of the derivative - may be difficult or
inconvenient to evaluate.
Then, the derivative can be approximated by a
backward finite divided difference:

f
'
(x
i
) ~
f (x
i1
) f (x
i
)
x
i1
x
i
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 27
OPEN METHODS
SECANT METHOD (contd)
Substitution of this approximation for the
derivative to the Newton-Raphson method
equation gives:
Note - this method requires two initial estimates
of x but does not require an analytical expression
of the derivative.

x
i+1
= x
i

f (x
i
) x
i1
x
i
( )
f (x
i1
) f (x
i
)
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 28
OPEN METHODS
The Secant Method
Homework: Write a general purpose Matlab programfor the
secant method
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 29
MATLABs fzero Function
MATLABs fzero provides the best qualities of both
bracketing methods and open methods.
Using an initial guess:
x = fzero(function, x0)
[x, fx] = fzero(function, x0)
function is a function handle to the function being evaluated
x0 is the initial guess
x is the location of the root
fx is the function evaluated at that root
Using an initial bracket:
x = fzero(function, [x0 x1])
[x, fx] = fzero(function, [x0 x1])
As above, except x0 and x1 are guesses that must bracket a sign
change
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 30
fzero Options
Options may be passed to fzero as a third input
argument - the options are a data structure created by
the optimset command
options = optimset(par
1
, val
1
, par
2
, val
2
,)
par
n
is the name of the parameter to be set
val
n
is the value to which to set that parameter
The parameters commonly used with fzero are:
display: when set to iter displays a detailed record of all the
iterations
tolx: A positive scalar that sets a termination tolerance on x.
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 31
fzero Example
options = optimset(display, iter);
Sets options to display each iteration of root finding
process
[x, fx] = fzero(@(x) x^10-1, 0.5, options)
Uses fzero to find roots of f(x)=x
10
-1 starting with an
initial guess of x=0.5.
MATLAB reports x=1, fx=0 after 35 function
counts
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 32
Polynomials
MATLAB has a built in program called roots to
determine all the roots of a polynomial - including
imaginary and complex ones.
x = roots(c)
x is a column vector containing the roots
c is a row vector containing the polynomial coefficients
Example:
Find the roots of
f(x)=x
5
-3.5x
4
+2.75x
3
+2.125x
2
-3.875x+1.25
x = roots([1 -3.5 2.75 2.125 -3.875 1.25])
Non-Linear Equations Roots Dr. Jorge A. Olortegui Yume, Ph.D. 33
Polynomials (cont)
MATLABs poly function can be used to determine
polynomial coefficients if roots are given:
b = poly([0.5 -1])
Finds f(x) where f(x) =0 for x=0.5 and x=-1
MATLAB reports b = [1.000 0.5000 -0.5000]
This corresponds to f(x)=x
2
+0.5x-0.5
MATLABs polyval function can evaluate a polynomial
at one or more points:
a = [1 -3.5 2.75 2.125 -3.875 1.25];
If used as coefficients of a polynomial, this corresponds to f(x)=x
5
-
3.5x
4
+2.75x
3
+2.125x
2
-3.875x+1.25
polyval(a, 1)
This calculates f(1), which MATLAB reports as -0.2500

You might also like