You are on page 1of 11

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 1

Prof. D.E. Smith

LECTURE 6
ROOTS OF EQUATIONS 2: OPEN METHODS
Motivation: Bracketing methods provide a robust approach for numerically computing the roots of a nonlinear equation. However, convergence is slow. Open methods are iterative numerical techniques for finding roots that typically converge faster than bracketing approaches.

Assigned Reading:

Chapra Chapter 6 (required)

MAE3100

LECURE 6 - 2

Prof. D.E. Smith

LECTURE 6 OBJECTIVES
The primary objective of this lecture is to gain a working knowledge of open methods used to compute the roots of a single nonlinear equation. More specifically, this lecture will: Recognize the difference between bracketing and open methods. Solve for roots using the fixed point iteration, Newton Raphson, and secant methods. Provide insight into how polynomials occur in engineering analysis. Show how to compute the roots of polynomials and other nonlinear functions with MATLAB.

LEC06_PT2_CH06 - open methods

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 3

Prof. D.E. Smith

Simple Fixed-Point Iteration


Also called one-point iteration or method of successive substitution. As with all open methods, the solution procedure begins with a single initial guess x1 Recall, we wish to solve f(x) = 0 f1

Rearrange to give:
Define iterative update For example: Let f(x) = e-x - x = 0 Then x = g(x) = e-x xi 1 e xi And

x = g(x)
xi+1 = g(xi) f2

Convergence is: asymptotic if 0 < g(x) < 1 oscillatory if -1 < g(x) < 0 error may grow when |g(x)| > 1

linear convergence

MAE3100

consider
f ( x) 1.5 x (1 x 2 ) 2

Simple Fixed Point Iteration - Example


0.65 tan
1

LECURE 6 - 4

Prof. D.E. Smith

1 x

0.65x 1 x2

solution
1 0.9

solving for x we obtain:


g ( x)
iter ----1 2 3 4 5 6 7

0.65 (1 x 2 ) 2 tan 1.5


xi --------0.1 0.606535 0.472035 0.481914 0.480744 0.480878 0.480863

1 x

0.65 x(1 x 2 ) 1.5

0.8 0.7 0.6

f1 = x

g(xi) --------0.606535 0.472035 0.481914 0.480744 0.480878 0.480863 0.480864

0.5 0.4 0.3 0.2 0.1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

f2 = g (x)

converged for | x g(x) | < 10-5

LEC06_PT2_CH06 - open methods

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 5

Prof. D.E. Smith

Newton-Raphson Iteration
Most widely used method for solving nonlinear equations Exhibits quadratic convergence (i.e., Ei+1 = Ei2) The solution procedure begins with a single initial guess x1 Requires the evaluation of both f (xi) and f (xi) at each iteration May be derived from a 1st order Taylor Expansion about xi Consider:
f ( x) f ( xi ) f ( xi )( x xi )

f (x) solution
f ( xi )

We desire f (xi+1) = 0, so that


f ( xi 1 ) f ( xi )( xi f ( xi ) xi ) f ( xi )( xi f ( xi )
1

xi )

f (xi) f (xi)

Then solving for xi+1


1

( xi

xi ) xi
1

f ( xi ) f ( xi ) f ( xi ) xi f ( xi )

xi+1
f ( xi )

xi

f ( xi )

MAE3100

Newton Raphson Iteration - Example


1.5 x (1 x 2 ) 2 0.65 tan
1

LECURE 6 - 6

Prof. D.E. Smith

consider
f ( x) 1 x 0.65x 1 x2
f (x)
0.2 0

where the derivative is:


f ( x) 2.8 3.2 x 2 (1 x 2 ) 3

-0.2

-0.4

iter ----1 2 3 4 5

xi ----------0.0 0.36465 0.46167 0.48019 0.48086

f (xi) -----------1.02102 -0.15841 -0.02197 -0.00074 -10-5

f (xi) ----------2.80000 1.63275 1.18627 1.10657

-f/f ----------0.36465 0.09702 0.01852 0.00067

-0.6

solution

-0.8

-1

-1.2

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

x converged for | f(x) | < 10-5

LEC06_PT2_CH06 - open methods

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 7

Prof. D.E. Smith

Newton Raphson Method


Advantages Converges rapidly in most cases (quadratic near root) Disadvantages May not converge if initial guess x0 is far from root May exhibit poor convergence in some special cases

MAE3100

LECURE 6 - 8

Prof. D.E. Smith

Newton Raphson Algorithm


1. 2. 3. 4. 5. 6. Choose convergence criteria and initial guess x1 Set iter = 1 Evaluate f (xiter) and f (xiter) Check |f (xiter)| < ? If yes then stop Check if iter > maximum iter? If yes then stop Update value of xiter using f ( xiter ) xiter 1 xiter f ( xiter )

7. Let iter = iter + 1 8. GOTO 3

LEC06_PT2_CH06 - open methods

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 9

Prof. D.E. Smith

Newton Raphson Pseudocode


PSEUDOCODE:
provide inputs as arguments including M-File name for f and f

FUNCTION nr1(x1, es, maxiter) xi = x1 DO iter = 1, maxiter f = f(xi) fp = f(xi) If | f | < es EXIT xi = xi f/fp use feval to call user-defined END DO M-File for f and f END nr1 Note: this is NOT a user-friendly NR program. It needs to be modified so that it will accommodate user defined functions and solution parameters (e.g., xi, imax, and es).

MAE3100

LECURE 6 - 10

Prof. D.E. Smith

MATLAB - feval
[y1,y2,...] = feval(func,x1,...,xn) Evaluates the function, func (usually defined by an M-file or built-in function), using arguments x1 through xn. the following are the same: >>sin(pi/4) >>feval(sin,pi/4) >>feval(@sin,pi/4)

LEC06_PT2_CH06 - open methods

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 11

Prof. D.E. Smith

Newton-Raphson feval Example


The following all perform the same computations:
Function M-file
function nr1(xi,imax,es) for i = 1:imax f = exp(-xi)-xi; fp = -exp(-xi)-1; disp([i xi f]); if abs(f)<es,break,end xi = xi - f/fp; end

Function M-files
function nr1(xi,imax,es) for i = 1:imax [f fp] = nrex1(xi); disp([i xi f]); if abs(f)<es,break,end xi = xi - f/fp; end

Function M-file
function nr1(func,xi,imax,es) for i = 1:imax [f fp]=feval(func,xi); disp([i xi f]); if abs(f)<es,break,end xi = xi - f/fp; end

function [g,dg] = nrex1(x) g = exp(-x)-x; dg = -exp(-x)-1;

function [g,dg] = nrex1(x) g = exp(-x)-x; dg = -exp(-x)-1;

Execution in MATLAB
>>nr1(1,25,1E-8)

Execution in MATLAB
>>nr1(1,25,1E-8)

Execution in MATLAB
>>nr1(nrex1,1,25,1E-8)

or
>>nr1(@nrex1,1,25,1E-8)

MAE3100

LECURE 6 - 12

Prof. D.E. Smith

The Secant Method


The solution procedure begins with 2 initial guesses x1 and x2 Exhibits super linear convergence (i.e., Ei+1 = Ei1.618) Requires the evaluation of f (xi) , but not f (xi) at each iteration Derived from the Newton Raphson update using the backwards finite difference method to approximate f (xi) Let
f ( xi ) f ( xi ) f ( xi 1 ) xi xi 1
f ( xi ) f ( xi ) xi 1 xi f ( xi ) , i f ( xi 1 ) f ( xi )
f (x) solution f (xi) f (xi+1)
~ f f

Then
xi
1

xi xi

2,3,4,...
xi+2 xi+1 xi
f ( xi ) ~ f

LEC06_PT2_CH06 - open methods

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 13

Prof. D.E. Smith

The Secant Method - Example


consider
f ( x)
iter ----1 2 3 4 5 : : : 13

1.5 x (1 x 2 ) 2
xi ----------0.0 0.5 0.49022 0.48540 0.48305

0.65 tan
f (xi) -----------1.02102 0.02035 0.01015 0.00497 0.00241

1 x

0.65x 1 x2

f (x)
0.2 0

xi+1 -----------0.49022 0.48540 0.48305 0.48192

-0.2

-0.4

-0.6

solution

-0.8

-1

0.48087

0.00000721

-1.2

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

x
converged for | f(x) | < 10-5

MAE3100

LECURE 6 - 14

Prof. D.E. Smith

Introduction to Polynomials
One goal of Chapter 6 is to determine the root(s) of an n-th order polynomial with (real) constant coefficients ai written as

f n ( x) a0 a1 x a2 x 2 an x n
The roots obey these rules: There are n real or complex roots All n roots are not necessarily distinct For odd n, there is at least 1 real root If there are complex roots, they occur in complex conjugate pairs, i.e.,

x1

a bi

x2

a bi

Consider: f (x) with 2 complex roots: a + bi and a - bi


f ( x) ( x (a bi))(x (a bi)) x 2 ax bix ax bix a 2 abi abi b 2i 2 x 2 2ax a 2 b 2

LEC06_PT2_CH06 - open methods

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 15

Prof. D.E. Smith

Engineering Application
Consider a spring-mass-damper system (i.e., an automotive suspension) Forces Spring force -kx c x Damper force External force F(t) From Newtons 2nd Law
F(t)

F (t ) kx cx

m x

m cx kx x

F (t )

The homogeneous or general solution is obtained for F(t) = 0, as

m cx kx 0 x
Assume a solution of the form x = ert

mr 2ert crert kert mr 2 cr k 0

Factoring out ert yields a 2nd order polynomial called the characteristic equation

MAE3100

LECURE 6 - 16

Prof. D.E. Smith

Engineering Example (cont)


The solution is obtained by finding the roots of the characteristic equation from the quadratic formula

r1 r2

c 2 4mk 2m

(3) (1)

Possible solutions: 1) 2 real roots when c

2 km
(2)

x(t )

Ae r1 t

Be r2 t

2) 2 complex roots when c 2 km


x(t ) e
t

( A cos t

B sin t )

c 2m

c 2 4mk 2m

3) Double root when c 2 km

x(t )

( A Bt )e

A and B determined from initial conditions

LEC06_PT2_CH06 - open methods

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 17

Prof. D.E. Smith

Finding Roots of Polynomials


Special techniques have been developed to compute real and complex roots of polynomial functions. These address issues such as: complex roots (not computed with bracketing methods) convergence problems (often seen in open methods) Mullers Method (Chapra and Canale s7.4) Fits a parabola to estimate root
f ( x)
x3 x2

a ( x x2 ) 2 b ( x x2 ) c
2c b b
2

Estimates new root with quadratic formula


4ac

Bairstows Method (Chapra and Canale s7.5) Divides the polynomial by x2 r x s Adjusts r and s until remainder vanishes Update process based on Newtons method Both are iterative and other more advanced methods exist

MAE3100

LECURE 6 - 18

Prof. D.E. Smith

Finding Roots of Polynomials (cont)


Roots may be computed by solving an Eigenvalue (see e.g. Appendix A) problem Consider the 5th order polynomial

a1 x5 a2 x 4 a3 x3 a4 x 2 a5 x a6
which may be rewritten as

a a2 4 a3 3 a4 2 a5 x x x x 6 a1 a1 a1 a1 a1 The companion matrix is formed using the right-hand-side of this equation as a a a a a x5


2 3 4 5 6

a1 1 0 0 0

a1 0 1 0 0

a1 0 0 1 0

a1 0 0 0 1

a1 0 0 0 0

whose Eigenvalues are the roots of the polynomial See eig in MATLAB

LEC06_PT2_CH06 - open methods

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 19

Prof. D.E. Smith

MATLAB fzero & roots


fzero finds the roots of a function of one variable syntax: fzero(func,x0,options) example: >> fzero(@sin,3) ans = 3.14159265358979

note, this also works:


fzero(inline('sin(a*x)','x','a'),3,[],1) roots finds the roots of a polynomial represented as an array p syntax: roots(p)

example:

find the roots of x3 6x2 72x 27


>> p = [1 -6 -72 -27]; >> roots(p) ans = NOTE: MATLAB represents 12.12289378463240 a polynomial as an array -5.73450994222507 where the elements of the -0.38838384240732

array are the coefficients of the polynomial

MAE3100

LECURE 6 - 20

Prof. D.E. Smith

MATLAB poly & polyval


poly

returns an array p with values that are the coefficients of a polynomial with roots r syntax: p = poly(r) p ( x) ( x 1)( x 1) example: find the polynomial having x2 x x 1 roots of 1 and -1 2
>> p = poly([1 -1]) p = 1 0 -1
x 1 (1) x 2 (0) x ( 1)

polyval evaluates a polynomial (represented as an array p) at x syntax: polyval(p,x)

example:

evaluate x3 6x2 72x 27 at x = 1


>> p = [1 -6 -72 -27]; >> polyval(p,1) ans = -104
p( x) x 3 6 x 2 72x 27

p (1) (1) 3 6(1) 2 72(1) 27 104

note that x may also be an array

LEC06_PT2_CH06 - open methods

10

MAE 3100 LEC 6

Prof. D.E. Smith

MAE3100

LECURE 6 - 21

Prof. D.E. Smith

MATLAB - polyder
polyder evaluates the derivative of a polynomial p or the product of the polynomials a and b syntax: polyder(p) polyder(a,b) example: for p(x) = x3 6x2 72x 27, find dp/dx
>> p = [1 -6 -72 -27]; >> polyder(p) ans = 3 -12 -72

example:

for a(x) = 3x2 + 6x + 9 and b(x) = x2 + 2x, find d(ab)/dx


>> a = [3 6 9]; >> b = [1 2 0]; >> k = polyder(a,b) k = 12 36 42

18

MAE3100

LECURE 6 - 22

Prof. D.E. Smith

MATLAB conv & deconv


evaluates the product of two polynomials a and b syntax: conv(a,b) deconv divides a polynomial c by another polynomial a syntax: deconv(c,a) conv example:
>> a = [1 -4 5.25 -2.5]; >> b = [1 -.5 .5]; >> c = conv(a,b) c = 1.0000 -4.5000 7.7500 >> deconv(c,a) ans = 1.0000 -0.5000 0.5000 >> deconv(c,b) ans = 1.0000 -4.0000 5.2500

-7.1250

3.8750

-1.2500

recovers b recovers a

-2.5000

LEC06_PT2_CH06 - open methods

11

You might also like