Solution of Nonlinear Equation (b)

32
1 Solution of Nonlinear Equation (b) Dr. Asaf Varol [email protected]

description

Solution of Nonlinear Equation (b). Dr. Asaf Varol [email protected]. Secant Method. Similar approach as the Newton-Raphson method Differs because the derivative does not need to be calculated analytically, which can be a great advantage F  (x i ) = [F(x i ) - F(x i-1 )]/(x i – x i-1 ) - PowerPoint PPT Presentation

Transcript of Solution of Nonlinear Equation (b)

Page 1: Solution of Nonlinear Equation  (b)

1

Solution of Nonlinear Equation (b)

Dr. Asaf Varol

[email protected]

Page 2: Solution of Nonlinear Equation  (b)

2

Secant Method

• Similar approach as the Newton-Raphson method

• Differs because the derivative does not need to be calculated analytically, which can be a great advantage

F(xi) = [F(xi) - F(xi-1)]/(xi – xi-1)

• Disadvantage is that two initial guesses are needed instead of one

)x(F)x(F

)xx)(x(Fxx

1ii

1iiii1i

Page 3: Solution of Nonlinear Equation  (b)

3

Graphical Interpretation of Newton-Raphson and Secant Method

  

Page 4: Solution of Nonlinear Equation  (b)

4

Example: Secant Method

• Water flow from a tower at a height h, through a pipe of diameter D and length L which is connected to the tower running vertically downward and then laid horizontally to the desired point of delivery. For this system the following equation for the flow rate Q is found. Find the roots using the Secant Method.

Page 5: Solution of Nonlinear Equation  (b)

5

Matlab Program

Page 6: Solution of Nonlinear Equation  (b)

6

Result for Secant Method

Page 7: Solution of Nonlinear Equation  (b)

7

Multiplicity of Roots and Newton-Based Methods

• In some situations, one root can fulfill the role of being a root more than one time. For example, the equation

F(x) = x3 - x2 - x + 1= (x + 1)(x - 1)2 = 0 

has three roots, namely x = -1, and x = 1 with a multiplicity of two• Using l’Hospital’s Rule, the Newton-Raphson method can be

modified

xi+1 = xi - F(xi)/F(xi)

Or, if the second derivative is also zero then l'Hospital's rule can be applied once more to obtain

xi+1 = xi - F(xi)/F(xi)

Page 8: Solution of Nonlinear Equation  (b)

8

Multiplicity of Roots and Newton-Based Methods

 

F(x)

(a)

+ +

x

Figure 2.4.1 Roots with multiplicity higher than one: (a) even multiplicity; (b) odd

F(x)

(b)

+

-x

Page 9: Solution of Nonlinear Equation  (b)

9

Example E2.4.1

Problem: Apply Newton-Raphson method to the polynomial equation 

F(x) = x3 - 3x2 + 3x - 1 = (x - 1)3 = 0 Solution: First we apply Newton-Raphson method without any modification of the given function. It can be shown that the method does not converge for any of the starting values x0 = 0., 0.5, 0.9, and 1.5. In fact the iterations oscillate between 0.2504306 and 0.4258722. But if we make the following substitution 

U(x) = F(x) and U(x) = F(x)  and apply the same method, i.e. 

xi+1 = xi - U(xi)/U(xi) then the method converges in 24 iterations to the root x=.9999999 with an error bound of 1.0E-07, and starting value of x=0.0

Page 10: Solution of Nonlinear Equation  (b)

10

Systems of Nonlinear Equations

• Extension of the previous methods to systems of N equations with N variables

• Our discussion will be limited to solutions to the following system of nonlinear equations:

F(x,y) = 0

G(x,y) = 0

• For example,

x2 + y2 - 2 = 0

-exp(-x) + y2 - 1 = 0

Page 11: Solution of Nonlinear Equation  (b)

11

Jacobi Iteration Method

• Jacobi method is an extension of the fixed-point iteration method to systems of equations

• The equations F(x,y) = 0 G(x,y) = 0

need to be transformed into

x = f(x,y)

y = g(x,y)

• Actual iteration is similar to the case of one equation with one variable

xi+1 = f(xi,yi)

yi+1 = g(xi,yi)

Page 12: Solution of Nonlinear Equation  (b)

12

Jacobi Iteration Method

• Convergence criteria - in the vicinity of the root (xr, yr),

1

y

f

x

f

1

y

g

x

g

Page 13: Solution of Nonlinear Equation  (b)

13

Example E2.5.1a

Problem: Solve the following systems of equations using Jacobi iteration method

x - 5 + exp(-xy) = 0

y - 1 + exp(-0.5x)cos(xy) = 0

Solution: First rewrite the equations in the form x = f(x, y), y = g(x,y)

x = 5 - exp(-xy)

y = 1 - exp(-0.5x)cos(xy)

We start with the initial guess x0 = 0, y0 = 0, and apply the Jacobi method with an error bound of 1.e-07.The result is shown in Table 2.5.1 which shows that the Jacobi iteration converges to the root x=4.9926,y=0.98372 in about 20 iteration. Note here the norm of the absolute error in x and in y is used as stoppingcriteria, i.e. ERROR = (errorx2 + errory2)1/2 < errbound.

Page 14: Solution of Nonlinear Equation  (b)

14

Matlab for Jacobi Method

• %Jacobi Iteration Method• x0=0.0;• y0=0.0• E=1.0E-4;• %• %---writing out headers to the file 'jacobimethod.dat'• %• fid=fopen('jacobi.dat','w');• fprintf(fid,'Roots of Equations x-5+exp(-xy)=0 \n\n')• fprintf(fid,'Roots of Equations y-1+exp(-0.5x)cos(xy)=0 \n\n') • fprintf(fid,'Using Jacobi Method \n')• fprintf(fid,'iter x y ErrorX ErrorY \n');• fprintf(fid,'------------------------------------------\n');• %• %---entering the loop to determine the root• %

Page 15: Solution of Nonlinear Equation  (b)

15

Matlab for Jacobi Method (Cont’d)

• for i=1:100• x1=5-exp(-x0*y0);• y1=1-exp(-0.5*x0)*cos(x0*y0);• errorx=abs(x1-x0);• errory=abs(y1-y0);• %---writing out results to the file 'jacobi method.dat'• %• fprintf(fid,'%4.1f %7.4f %7.4f %7.4f %7.4f \n',i,x1,y1,errorx,errory);• %• • if abs(x1-x0)<E&abs(y1-y0)<E• break; • end• • x0=x1;• y0=y1;• • end• fclose(fid)• disp('Roots approximation=')• x1,y1

Page 16: Solution of Nonlinear Equation  (b)

16

Results for Jacobi Method

Page 17: Solution of Nonlinear Equation  (b)

17

Gauss-Seidel Iteration Method

• Similar to the Jacobi iteration method• Differs by using updated x or y values (i.e. the approximate

roots) for calculations

i + 1*

i ix = f ( x , y )

i + 1 i + 1*

iy = g ( x , y )

o r in t h e r e v e r s e o r d e r

i + 1*

i iy = g ( x , y )

i + 1 i i + 1*x = f ( x , y )

Page 18: Solution of Nonlinear Equation  (b)

18

Newton’s Method (I)

• Consider the two nonlinear equations

F(x,y) = 0

G(x,y) = 0

• The Taylor series expansion for a function F(x, y) is

where ( )x and ( )xx denote the first and second partial derivatives with respect to x, and similarly for ( )y , ( )yy and ( )xy

...+/2)y-)(yy,x(F+/2)x-)(xy,x(F

+ )/2y-)(yx-)(xy,x(F+)y-)(yy,x(F

+)x-)(xy,x(F + )y,x F(= y)F(x,

2oooyy

2oooxx

ooooxyoooy

oooxoo

Page 19: Solution of Nonlinear Equation  (b)

19

Newton’s Method (II)

• Keeping the first three terms on the right-hand side yields

• Solving these equations for x and y after letting

yields

where J is the Jacobian defined by J = (FxGy - GxFy)

J

)FG - G(F - x x

yy

y=y,x=x

i1+i

ii

J

)G F- F(G - y y xx

y=y,x=xi1+i

ii

Page 20: Solution of Nonlinear Equation  (b)

20

Newton’s Method (III)

• Retaining only two terms and thus simplifying the equations,

ii y,xxi1i F

Fxx

ii y,xyi1i G

Gyy

where andx

FFx

y

GG y

Page 21: Solution of Nonlinear Equation  (b)

21

Technique of Underrelaxation and Overrelaxation

• Expresses ‘confidence’ in the new estimate of the root

• Underrelaxation 0 < < 1

• Overrelaxation - 1 < < 2

• Can be applied to Newton’s method as

i1i1i x1xx

i1i1i x1yy

ii y,xxi1i F

Fxx

ii yxyii G

Gyy,

1

Page 22: Solution of Nonlinear Equation  (b)

22

Case Study C2.2: Two Intersecting Circles

I n v a r i o u s e n g i n e e r i n g a p p l i c a t i o n s , m e a s u r e m e n t s o f fl u i d v e l o c i t y u s i n g l a s e r D o p p l e ra n e m o m e t e r ( L D A ) i t i s n e c e s s a r y t o d e t e r m i n e i f a n d w h e r e t w o c i r c l e s i n t e r s e c t e a c ho t h e r w h e n t h e r a d i i a n d t h e l o c a t i o n o f t h e c o o r d i n a t e s o f t h e c e n t e r s a r e g i v e n . I n t h i sc a s e , w i t h o u t l o s s o f g e n e r a l i t y , o n e c a n p u t t h e o r i g i n o f t h e c o o r d i n a t e s y s t e m a t t h ec e n t e r o f o n e o f t h e c i r c l e s , h e n c e t h e e q u a t i o n s a r e

x y r2 21

2

( ) ( )x x y y rc c 2 22

2

w h e r e ( x c , y c ) i s t h e c o o r d i n a t e s o f t h e c e n t e r o f t h e s e c o n d c i r c l e . G i v e n f o r e x a m p l e ,x c = 1 , y c = 1 , r 1 = 1 , r 2 = 1 , fi n d t h e p o i n t s o f i n t e r s e c t i o n o f t h e s e t w o c i r c l e s .

Page 23: Solution of Nonlinear Equation  (b)

23

Case Study C2.2: Two Intersecting Circles (Cont’d)

S o l u t i o n : T h e N e w t o n - R a p h s o n i t e r a t i o n m e t h o d d e r i v e d f o r t w o e q u a t i o n s c a n b eu s e d w i t h r e l a t i v e e a s e t o fi n d t h e r o o t s o f t h e a b o v e g i v e n e q u a t i o n s . L e t

F x y x y( , ) 2 2 1 0

G x y x y( , ) ( ) ( ) 1 1 1 02 2

T h e p a r t i a l d e r i v a t i v e s a r e

F x = 2 x ; F y = 2 y ; G x = 2 ( x - 1 ) ; G y = 2 ( y - 1 )

a n d t h e J o c o b i a n i s g i v e n b y

J = ( F x G y - G x F y )

w h e r e ( ) x d e n o t e s t h e p a r t i a l d e r i v a t i v e w i t h r e s p e c t t o x , a n d s i m i l a r l y f o r y . T h e e x a c tr o o t s o f t h e a b o v e e q u a t i o n s c a n b e f o u n d b y i n s p e c t i o n o f t h e e q u a t i o n t o b e ( 1 , 0 ) a n d( 0 , 1 ) . W i t h a n i n i t i a l g u e s s o f x = 0 . 5 , y = 0 . 1 f o r t h e fi r s t r o o t , a n d x = 0 . 1 , y = 0 . 5 f o rt h e s e c o n d r o o t , t h e r o o t s a r e f o u n d t o b e :

( i ) x r = 1 . 0 0 0 0 1 3 , y r = - 1 . 3 1 0 1 9 0 e - 0 5 ; ( i i ) x r = - 1 . 3 1 0 1 9 0 e - 0 5 , y r = 1 . 0 0 0 0 1 3

Page 24: Solution of Nonlinear Equation  (b)

24

Case Study C2.3: Damped Oscillation of an Object

T h e d a m p e d o s c i l l a t i o n o f a n o b j e c t a s s e e n i n t h e F i g u r e b e l o w i s g o v e r n e d b y N e w t o n ’ s s e c o n d l a w .

F i g u r e C . 2 . 3 a M a s s - s p r i n g s y s t e m w i t h d a m p e r .

k s p r i n g m o b j e c t

c f l u i d

( m a s s ) ( a c c e l e r a t i o n ) = ( n e t f o r c e a c t i n g o n t h e o b j e c t )

F o r t h i s p r o b l e m t h i s e q u a t i o n c a n b e w r i t t e n a s

m a = - c v - k x

w h e r e m i s t h e m a s s ( i n k g ) , a i s t h e a c c e l e r a t i o n , c i s t h e d a m p i n g c o e ffi c i e n t ( i n k g / s ) , k ( i n k g / s ) i st h e s p r i n g c o n s t a n t , a n d x i s t h e d i s p l a c e m e n t d i s t a n c e f r o m a n e q u i l i b r i u m p o s i t i o n . T h e a b o v ee q u a t i o n c a n a l s o b e w r i t t e n a s

md x

d t

d x

d t

2

2 + c + k x = 0 . x = x 0 ; v = 0 . a t t = 0 .

Page 25: Solution of Nonlinear Equation  (b)

25

Case Study C2.3: Damped Oscillation of an Object (continued)

The analytical solution to this problem can be found knowing the fact that this is an oscillatory motion, andit is damped by a viscous fluid, so the displacement should go to zero for large time, i.e. as t goes toinfinity. A solution of the form

x =x0 exp(-bt) [ ACos(t) + BSin(t) ]

is first assmed. In order to satisfy the initial conditions we must have A = 1 ; B = b/

Substituting the proposed solution in to the differential equation and equating the coefficients of Cos(t) andSin(t) to zero( note that the r.h.s. of the differential equation must be zero for arbitrary time) yields thefollowing relation for two unknowns

b = c/(2m) ; = [ (k/m) - (c2/4m2)]1/2

For a meaningful solution it is necessary to have

c2 < 4mk

Given that c= 100 kg/s, k = 10,000 kg/s2, and m=50 kg(i) Determine the time after which the oscillations of the object would be less than 10% of its initialdisplacement.(ii) Determine the first time at which the object will pass through the equilibrium point, i.e. x=0.(iii) Given the above values of c and k, determine m such that the object passes the zero pint at t=0.20seconds for the first time.

Page 26: Solution of Nonlinear Equation  (b)

26

Case Study C2.3: Damped Oscillation of an Object (continued)

Solution (i): First we calculate the parameters b and which are:

b =1. sec-1 ; =14.11 sec-1

To solve problem (i) it is not necessary to use any numerical method. But we first plotthis function as a function of time to observe the general behavior of it. Figure C2.3bshows how the objects oscillates in a periodic manner with decaying amplitude. To findout when the amplitude will be less than 0.1, we first find where the function will havelocal maxima or minima by setting the first derivative of the function w.r.t. to timeequal to zero. This yields the information that

Sin(t) = 0. or Cos(t) = 1

where the function will have a local maximum or a minimum. Thus we have

0.1 = exp(-bt) [1.0 +0.0]

to find the answer to the first part, which is t = 2.3 seconds.

Page 27: Solution of Nonlinear Equation  (b)

27

Case Study C2.3: Damped Oscillation of an Object (continued)

Solution (ii): Part (ii) requires the solution of

0 = exp(-bt) [ Cos(t) + c/(2m)Sin(t) ]

Since exp(-bt) is never zero we divide both sides by this to get

F(t) =Cos(t) + c/(2m)Sin(t) ] = 0.

Using the bisection method with the given values of the parameters and the lower andupper bounds tlower = 0., tupper=0.2, we find the answer to Part (ii) to be

t = 0.11636 seconds

Note that this problem can also be solved using the Newton-Raphson method, thedifferentiation w.r.t. time is not so difficult.

Page 28: Solution of Nonlinear Equation  (b)

28

Case Study C2.3: Damped Oscillation of an Object (continued)

time (seconds)

0 1 2 3

x/x

0

-1.0

-0.5

0.0

0.5

1.0

Figure C2.3b Variation of X/X0 with time: m = 50 kg ;

k = 1.0E+04 kg/s2; c =1.0E+02 kg/s

Page 29: Solution of Nonlinear Equation  (b)

29

Case Study C2.3: Damped Oscillation of an Object (continued)

Solution to part (iii): In this case the dependent variable is the mass, m, not the time. So we first plot thefunction making m the independent variable as seen in the figures. The first figure is generated by scanning thefunction at 0.5 kg intervals. As mentioned before without using some analytical analysis and without usingengineering judgment it is difficult to guess where approximately the roots of the equation would be. Thisproblem is a good example in that for a fixed time, in this case t=0.2 s, it seems as if there should be only one(unique) mass, m. It is seen from the graphs that this is not the case. Inspection of the graph carefully reveals thatthere are roots in the following intervals:

(0.5, 1.0) ; (1.5, 2.0) ; (2.5, 3.0) ; (5.5, 6.0) ; (16.5, 17.0) ; (153.5, 154)

and so on. However, it is difficult to locate all of these points from the first figure. For this, the portion of thegraph is enlarged and replotted in the second figure where it is possible to see the roots in the interval (0.5, 7.0).Inspection of the table of values for this function for m < 0.5 reveals that the function becomes almost chaotic inthis region with many more roots. Therefore, a proper statement of part (iii) should specify the interval for whicha solution is being sought. For example it could be as follows:“Determine the possible values of m in the interval (10,20) such that the object crosses the equilibrium point(x=0.) at time t=0.2 seconds for the first time.” To solve this problem we apply the bisection method withthe lower and upper bounds 10 and 20, respectively with the following function subprogram. It is seen theroot in the interval is

m = 16.861 kg

with an error bound of 1.E-04

Now, to make sure that with this value of mass, the displacement is zero at timet = 0.2 seconds for the first time, the function should be plotted again where x/x0 versus time is displayed.

Page 30: Solution of Nonlinear Equation  (b)

30

Case Study C2.3: Damped Oscillation of an Object (continued)

mass (kg)

0 20 40 60 80 100 120 140 160 180 200

x/x 0

-1.0

-0.5

0.0

0.5

1.0

Figure C2.3c Variation of X/X0 with mass: t = 0.2 kg ;

k = 1.0E+04 kg/s2; c =1.0E+02 kg/s

mass (kg)

0 1 2 3 4 5 6 7

x/x 0

-0.10

-0.05

0.00

0.05

0.10

Figure C2.3d Variation of X/X0 with mass: t = 0.2 kg ;

k = 1.0E+04 kg/s2; c =1.0E+02 kg/s

Page 31: Solution of Nonlinear Equation  (b)

31

End of Chapter 2b•

Page 32: Solution of Nonlinear Equation  (b)

32

References• Celik, Ismail, B., “Introductory Numerical Methods for Engineering Applications”,

Ararat Books & Publishing, LCC., Morgantown, 2001 • Fausett, Laurene, V. “Numerical Methods, Algorithms and Applications”, Prentice

Hall, 2003 by Pearson Education, Inc., Upper Saddle River, NJ 07458

• Rao, Singiresu, S., “Applied Numerical Methods for Engineers and Scientists, 2002 Prentice Hall, Upper Saddle River, NJ 07458

• Mathews, John, H.; Fink, Kurtis, D., “Numerical Methods Using MATLAB” Fourth Edition, 2004 Prentice Hall, Upper Saddle River, NJ 07458

• Varol, A., “Sayisal Analiz (Numerical Analysis), in Turkish, Course notes, Firat University, 2001