Roots of Equations - Civil and Environmental Engineering | SIU

Download Report

Transcript Roots of Equations - Civil and Environmental Engineering | SIU

ROOTS OF EQUATIONS

ENGR 351 Numerical Methods for Engineers Southern Illinois University Carbondale College of Engineering Dr. L.R. Chevalier Dr. B.A. DeVantier

Copyright © 2003 by Lizette R. Chevalier and Bruce DeVantier Permission is granted to students at Southern Illinois University at Carbondale to make one copy of this material for use in the class ENGR 351, Numerical Methods for Engineers. No other permission is granted.

All other rights are reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the copyright owner.

Applied Problem

The concentration of pollutant bacteria C in a lake decreases according to:

C

 80

e

 2

t

 20

e

 .

t

Determine the time required for the bacteria to be reduced to 10 ppm.

Applied Problem

You buy a $20 K piece of equipment for nothing down and $5K per year for 5 years. What interest rate are you paying? The formula relating present worth (P), annual payments (A), number of years (n) and the interest rate (i) is:

A

P

 1

i

 1  

i

n i

n

 1

Quadratic Formula

x

b

2  4

ac

ax

2 2

a

bx

0 This equation gives us the roots of the algebraic function f(x) i.e. the value of x that makes f(x) = 0 How can we solve for f(x) = e -x - x?

Roots of Equations

 Plot the function and determine where it crosses the x-axis  Lacks precision 10  Trial and error 8 6 4 2 0 -2 -2 -1 0

x

1 2

Overview of Methods

 Bracketing methods  Graphing method   Bisection method False position  Open methods  One point iteration   Newton-Raphson Secant method

Specific Study Objectives

   Understand the graphical interpretation of a root Know the graphical interpretation of the false-position method (regula falsi method) and why it is usually superior to the bisection method Understand the difference between bracketing and open methods for root location

Specific Study Objectives

 Understand the concepts of convergence and divergence.  Know why bracketing methods always converge, whereas open methods may sometimes diverge  Realize that convergence of open methods is more likely if the initial guess is close to the true root

Specific Study Objectives

    Know the fundamental difference between the false position and secant methods and how it relates to convergence Understand the problems posed by multiple roots and the modification available to mitigate them Use the techniques presented to find the root of an equation Solve two nonlinear simultaneous equations

Bracketing Methods

 Graphical  Bisection method  False position method (regula falsi method)

Graphical

(limited practical value) f(x) x consider lower and upper bound same sign, no roots or even # of roots f(x) f(x) f(x) opposite sign, odd # of roots x x x

Bisection Method

 Takes advantage of sign changing  f(x l )f(x u ) < 0 where the subscripts refer to lower and upper bounds  There is at least one real root f(x) f(x) f(x) x x x

Algorithm

   Choose x u  and x l . Verify sign change f(x l )f(x u ) < 0 Estimate root  x r = (x l + x u ) / 2 Determine if the estimate is in the lower or upper subinterval    f(x l )f(x r ) < 0 then x u f(x l )f(x r ) >0 then x l = x = x r r RETURN RETURN f(x l )f(x r ) =0 then root equals x r - COMPLETE

Algorithm

   Choose x u  and x l . Verify sign change f(x l )f(x u ) < 0 Estimate root  x r = (x l + x u ) / 2 Determine if the estimate is in the lower or upper subinterval  f(x l )f(x r ) < 0 then x u = x r RETURN

Algorithm

   Choose x u  and x l . Verify sign change f(x l )f(x u ) < 0 Estimate root  x r = (x l + x u ) / 2 Determine if the estimate is in the lower or upper subinterval  f(x l )f(x r ) >0 then x l = x r RETURN

Algorithm

   Choose x u  and x l . Verify sign change f(x l )f(x u ) < 0 Estimate root  x r = (x l + x u ) / 2 Determine if the estimate is in the lower or upper subinterval    f(x l )f(x r ) < 0 then x u f(x l )f(x r ) >0 then x l f(x l )f(x r ) =0 = x = x r r RETURN RETURN then root equals x r - COMPLETE

Error

a

present approx

.

previous approx

present

100 Let’s consider an example problem:

Example

Use the bisection method to determine the root •f(x) = e -x - x •x l = -1 x u = 1 10 8 6 4 2 0 -2 -2 -1 3.7 18282 0

x

1 -0.63212

2

False Position Method

 “Brute Force” of bisection method is inefficient  Join points by a straight line  Improves the estimate  Replacing the curve by a straight line gives the “false position”

next estimate, x r x l f(x l ) x u f(x u ) Based on similar triangles

x r

 

l

x l

x r

u x u x r

x u

  

u

 

l

x l

f x x u u

  

Example

Determine the root of the following equation using the false position method starting with an initial estimate of x

l

=4.55 and x

u

=4.65

f(x) = x

3

- 98

-10 -20 -30 -40 30 20 10 0 4 4.5

x

5

Pitfalls of False Position Method

f(x)=x 10 -1

30 25 20 15 10 5 0 -5 0 0.5

1

x

1.5

Open Methods

 Newton-Raphson method  Secant method  Multiple roots  In the previous bracketing methods, the root is located within an interval prescribed by an upper and lower boundary

Open Methods cont.

 Such methods are said to be convergent  solution moves closer to the root as the computation progresses  Open method  single starting value   These solutions may diverge  two starting values that do not necessarily bracket the root solution moves farther from the root as the computation progresses

f(x) x i f(x i+1 ) x i+1 The tangent gives next estimate.

x f(x i )

f(x) x 2 Solution can “overshoot” the root and potentially diverge x 1 x 0 x

Newton Raphson

tangent f(x i ) x i+1 x i

tangent f

'  

i

 

dy dx

 

i

 

x i

x i

 1

f

0 '

rearrange x i

 1

i f

'  

x i

 

i

Newton Raphson Pitfalls

f(x) (x)

Newton Raphson Pitfalls

solution diverges f(x) (x)

Example

Use the Newton Raphson method to determine the root of f(x) = x 2 - 11 using an initial guess of x i = 3 100 80 60 40 20 0 -20 0 2 4

x

6 8 10

Solution

 f(x) = x 2  f '(x) = 2x - 11   initial guess x i f(3) = -2  f '(3) = 6 = 3 100 80 60 40 20 0 -20 0 2 4

x

6 8 10

Solution

x i

 1 

a

 '  

i

 

i

6    3  100  10% In this method, we begin to use a numbering system: x 0 x 1 = 3 = 3.33

Continue to determine x 2 , x 3 etc.

Solution

x

2 

a x

3 

a

   

x

1 

f f

'   1   1  3 .

33  3 .

315  3 .

33  100 

x

2  3 .

f f

315 '   2   2  3 .

315   0 .

11  6 .

66   3 .

315 0 .

55 %  0 .

0108  6 .

63  3 .

317 3 .

317  3 .

315  100  0 .

05 % 3 .

317

Secant method

Approximate derivative using a finite divided difference

f

'   

i

1

x i

 1  

x i

 

i

What is this? HINT: dy / dx = D y / D x Substitute this into the formula for Newton Raphson

x i

 1 

x i

f f

'  

i

 

i x i

 1 

x i

f f

 

i

 

i

1

x i

  1

f

x i

 

i

 Substitute finite difference approximation for the first derivative into this equation for Newton Raphson

Secant method

Secant method

x i

 1 

x i

f f

 

i x i

 1 

x i

   

i

1

i

  Requires two initial estimates f(x) is not required to change signs, therefore this is not a bracketing method

Secant method

f(x) Select two estimates.

Note: f(x i ) and f(x i+1 ) are not opposite signs.

x initial estimates

Secant method

f(x) slope between two estimates x initial estimates

Secant method

f(x) slope between two estimates new estimate x initial estimates

Example

Determine the root of f(x) = e -x - x using the secant method. Use the starting points x 0 = 0 and x 1 = 1.0.

10 8 6 4 2 0 -2 -2 -1 0

x

1 2

Solution

 Choose two starting points    x 0 = 0 f(x 0 ) =1 x 1 = 1.0 f(x 1 ) = -0.632

Calculate x 2  x 2 = 1 - (-0.632)(0 - 1)/(1+0.632) = 0.6127

Solution

   Second iteration    x 1 = 1.0 f(x 1 ) = -0.632

x 2 = 0.613 f(x 2 ) = -0.0708

NOTE: f(x) are the same sign. OK here.

x 3 = 0.613 - (-0.0708)(1-0.613)/( 0.632+0.0708) x 3  = 0.564 f(x 3 ) = 0.0052

 a = abs[(0.564-0.613)/(0.564)] x 100 = 8.23%

Solution

 Third iteration     x 2 x 3 = 0.613 f(x 2 ) = -0.0708

= 0.564 f(x 3 ) = 0.0052

 x 4 = 0.567 f(x 4 ) = -0.00004

 a = 0.59%  t = 0.0048% Know the difference between these error terms

Comparison of False Position and Secant Method 2 f(x) 2 f(x) 1 1 new est.

x new est.

x

f(x) FALSE POSITION 1 SECANT METHOD x f(x) 1 - select first estimate x

f(x) FALSE POSITION 2 1 x f(x) 1 SECANT METHOD 2 - select second estimate x

f(x) FALSE POSITION 2 1 x f(x) 1 SECANT METHOD 2 Note the sign of f(x) in each method.

False position must bracket the root.

x

f(x) FALSE POSITION 2 1 x f(x) 1 SECANT METHOD 2 - Connect the two points with a line x

f(x) FALSE POSITION 2 1 new est.

The new estimate is selected from the intersection with the x-axis x f(x) 1 SECANT METHOD 2 new est.

x

Multiple Roots

 Corresponds to a point where a function is tangential to the x-axis  i.e. double root  f(x) = x 3 - 5x 2 + 7x -3 10 8 6 4   f(x) = (x-3)(x-1)(x-1) i.e. triple root 2 0 -2 -4  f(x) = (x-3)(x-1) 3 0 m ultiple root 1 2

x

3 4

Difficulties

 Bracketing methods won’t work  Limited to methods that may diverge 2 0 -2 -4 10 8 6 4 0 m ultiple root 1 2

x

3 4

 f(x) = 0 at root  f '(x) = 0 at root  Hence, zero in the denominator for Newton Raphson and Secant Methods  Write a “DO LOOP” to check is f(x) = 0 before continuing 10 8 6 4 2 0 -2 -4 0 m ultiple root 1 2

x

3 4

Multiple Roots

x i

 1 

x i

 

f

'  2  2 0 -2 -4 10 8 6 4 0 m ultiple root 1 2

x

3 4

Systems of Non-Linear Equations

 We will later consider systems of linear equations    f(x) = a 1 x 1 where a 1 + a , a 2 2 x 2 +...... a .... a n n x n - C = 0 and C are constant Consider the following equations   y = -x 2 + x + 0.5

y + 5xy = x 3  Solve for x and y

Systems of Non-Linear Equations cont.

 Set the equations equal to zero   y = -x 2 + x + 0.5

y + 5xy = x 3  u(x,y) = -x 2 + x + 0.5 - y = 0  v(x,y) = y + 5xy - x 3 = 0  The solution would be the values of x and y that would make the functions u and v equal to zero

Recall the Taylor Series

 

i

1 

i

f

'  

i

. . . . . .

where h

f n

 

i h n n

!

step size

  

R n f

' '  

i h

2 2 !

x i

 1 

x i

f

' ' '  

i h

3 3 !

Write a first order Taylor series with respect to u and v

u i

 1 

u i v i

 1 

v i

  

u i

x

v i

x

x i

 1 

x i

 1  

x i x i

    

u i

y

v i

y

y i

 1 

y i

 1  

y i y i

  The root estimate corresponds to the point where u i+1 = v i+1 = 0

Therefore

x i

 1

y i

 1 

x i

y i

  

u i

x u i

v i

y

v

y i

u i

x u i

v i

y

v i

y

  

u v i

u i

y

y

v

x i

  

u v i

u i

y

y

v i

x

This is a 2 equation version of Newton-Raphson

Therefore

x i

 1

y i

 1 

x i

y i

  

u i

x u i

v i

y

v

y i

u i

x u i

v i

y

v i

y

  

u v i

u i

y

y

v

x i

  

u v i

u i

y

y

v i

x

THE DENOMINATOR OF EACH OF THESE EQUATIONS IS FORMALLY REFER RED TO AS THE DETERMINANT OF THE JACOBIAN This is a 2 equation version of Newton-Raphson

Example

 Determine the roots of the following nonlinear simultaneous equations  y = -x 2 + x + 0.5

 y + 5xy = x 3  Use and initial estimate of x=0, y=1

Solution

i 1 2 3 4 5 6 7 8 9 x y u v dvdx dudx dvdy dudy J 0 1 -0.5

1 5 1 1 -1 6 -0.083 0.41 7 0.0828 0.244 2.063 1 .1 67 0.583 -1 .000 2.743

-0.1 90 0.375 0.1 1 79 0.026 1 .768 1 .380 0.051 -1 .000 1 .839

-0.207 0.469 0.022

-0.008 2.21 7 1 .41 4 -0.036 -1 .000 2.1 66 -0.203 0.497 -0.005 0.001 2.360 1 .406 -0.01 6 -1 .000 2.338

-0.203 0.491 0.0004 0.000 2.332 1 .407 -0.01 7 -1 .000 2.308

-0.203 0.492 0.0000 0.000 2.334 1 .407 -0.01 7 -1 .000 2.31 0 -0.203 0.492 0.0000 0.000 2.334 1 .407 -0.01 7 -1 .000 2.31 0 -0.203 0.492 0.0000 0.000 2.334 1 .407 -0.01 7 -1 .000 2.31 0 -0.203 0.492 0.0000 0.000 2.334 1 .407 -0.01 7 -1 .000 2.31 0 See file

nonlinear simultaneous.xls

Applied Problem

The concentration of pollutant bacteria C in a lake decreases according to:

C

 80

e

 2

t

 20

e

 .

t

Determine the time required for the bacteria to be reduced to 10 using Newton-Raphson method.

Applied Problem

You buy a $20 K piece of equipment for nothing down and $5K per year for 5 years. What interest rate are you paying? The formula relating present worth (P), annual payments (A), number of years (n) and the interest rate (i) is:

A

P

 1

i

 1  

i

n i

n

 1 Use the bisection method

Previous Quiz

Graphically illustrate the Newton Raphson Method and bi-section method for finding the roots of an equation on graphs provided. Only show two iterations. Be sure to select initial guesses which avoid pitfalls (i.e. zero slope).

Previous Quiz

Given the Taylor series approximation, describe the detail given by a) zero order approximation; b) first order approximation; c) second order approximation.

 

i

1 

i

f

'  

i

. . . . . .

where h

f n

 

i h n n

!

step size

  

R n f

' '  

i h

2 2 !

x i

 1 

x i

f

' ' '  

i h

3 3 !

Previous Exam Question

Given the equation: f(x) = x 4 - 3x 2 + 6x -2 = 0 a) Indicate on the graph an initial estimate for the Newton Raphson Method where - the solution will diverge - a reasonable choice b) Solve to three significant figures