You are on page 1of 14

MMA307 lecture 6: Nonlinear equations III

MMA307 lecture 6: Nonlinear equations III


Feb 5, 2014

Newton-Raphson Method Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

Division of Applied Mathematics Mlardalen University


1

Contents of todays Lecture

MMA307 lecture 6: Nonlinear equations III

Newton-Raphson Method

1 Newton-Raphson Method

Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

2 Newton-Raphson method-MATLAB Implementation

3 Other topics to be covered on the whiteboard

4 Homework 6

Coming next in this course

MMA307 lecture 6: Nonlinear equations III

Newton-Raphson Method Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

Polynomial approximation and interpolation (lec. 7, 8) Curve tting (regression, spline interpolation) (lec. 7, 8) Simultaneous linear equations (lec. 9) Numerical integration (lec 10) Ordinary differential equations (lec 11)

Newton-Raphson Method-graphical illustration

MMA307 lecture 6: Nonlinear equations III

Newton-Raphson Method Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

Your tangent lines in this case will eventually pass by the zero of the function.

Newton-Raphson Method-Formula

MMA307 lecture 6: Nonlinear equations III

Newton-Raphson Method Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

Slope of the tangent line = rise/run, i.e. f (xi ) = f (xi ) xi xi +1

f (xi )(xi xi +1 ) = f (xi ) f (xi )xi f (xi )xi +1 = f (xi ) f (xi )xi f (x ) = f (xi )xi +1 xi +1 = f (xi )xi f (xi ) f (xi ) f (x ) f (xi )
5

= xi

Newton-Raphson Method-Algorithm

MMA307 lecture 6: Nonlinear equations III

Newton-Raphson Method

1 Calculate f (x ) symbolically. 2 Choose an initial guess x0 . 3 Compute x1 = x0 f (x0 ) , and in general xi +1 = xi f (xi ) 0 i Compute the (Absolute) relative approximation error x0 Rapprox = | x1x | 1 If Rapprox < tol , where tol is some pre-specied
tolerance, then stop the algorithm, x1 is our estimated root. Otherwise, go back to step 3.
f (x ) f (x )

Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

Question Are there any risk of innite loop in this algorithm?

Newton-Raphson Method-example
Example

MMA307 lecture 6: Nonlinear equations III

Finding root of nonlinear equation x 3 + x 1 = 0, take x0 = 0.6. f (x ) = 3x 2 + 1, so the Newton-Raphson formula is


Solution

Newton-Raphson Method Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard

xi +1 = xi xi +1 = xi

f (x ) f (x ) xi3 + xi 1 3x 2 + 1 2xi3 + 1 3xi2 + 1

Homework 6

Iterating this formula from initial guess x0 = 0.6 gives x1 = 2(0.6)3 + 1 3(0.6)2 + 1

0.2731

x2 = 0.8505, x3 = 0.7036, x4 = 0.6827 x5 = 0.6823, x6 = 0.6823, . . .


7

Newton-Raphson Method-FPI

MMA307 lecture 6: Nonlinear equations III

Newton-Raphson Method

Use your FPI function to solve the function cos(x ) = x , with starting point x0 = 1 To solve this equation, you may introduce a function f (x ) = x cos(x ). How many iterations are needed for covergence to 6 decimals? Apply this function in the Newton Raphsons method and use your FPI function to solve the equation again. How many iterations are needed for convergence?

Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

Remember, the order of convergence

MMA307 lecture 6: Nonlinear equations III

Denition (Mathews (2004))

Newton-Raphson Method Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

Assume that {pn } n=0 converges to p and set En = p pn for n 0. If two positive constants A = 0 and R > 0 exist, and

|p pn+1 | |En+1 | lim = lim =A n |p pn |R n |En |R


The sequence is said to converge to p with order of convergence R . The number A is called the asymptotic error constant. The case R = 1, 2 are given special consideration.

If R = 1, the convergence of {pn } n=0 is called linear. If R = 2, the convergence of {pn } n=0 is called quadratic.

Convergence property of Newton-Raphson method


Theorem (Sauer 2014)

MMA307 lecture 6: Nonlinear equations III

Let f be twice continuously differentiable and f (r ) = 0. If f (r ) = 0, then Newtons Method is locally and quadratically convergent to r . The error ei at step i satises lim ei +1 ei2

Newton-Raphson Method Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

=M

where M=

f (r ) 2f (r )

If Newton-Raphson method converges-does it always obey quadratic convergence? Exercise: compute M in the previous exercise where f (x ) = x 3 + x 1 = 0.
10

Newton-Raphson Method-MATLAB function

MMA307 lecture 6: Nonlinear equations III

function x =newton1(f,df,x0,tol1,tol2, iterNr) %Input - f is the function in f(x) =0 Newton-Raphson % - df is the derivative of f method-MATLAB Implementation % - x0 is the initial guess % - tol1 is the tolerance for xo Other topics to be covered on the % - tol2 is the tolerance for the function values y whiteboard % - iterNr is the maximum number of iterations Homework 6 %Output - x is the sequence of estimates x(1) =x0; for k=2: iterNr x(k)=x(k-1)-f(x(k-1))/df(x(k-1)); err=abs(x(k)-x(k-1)); y=f(x(k)); if (err<tol1)|(abs(y)<tol2),break,end end x=x
Newton-Raphson Method

11

More topics to be covered in the lecture

MMA307 lecture 6: Nonlinear equations III

Newton-Raphson Method Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

Advantages and drawbacks of Newton-Raphson method. Secant method.

12

Homework 6-nonlinear equations III

MMA307 lecture 6: Nonlinear equations III

Newton-Raphson Method

Section 2.4, ex 3, 4 (Mathews page 85), compute by hand (calculator/excel etc), dont use the Matlab function. Plot the error sequence for 20 iterations of the previous exercise. Write a MATLAB Function that takes a function f and a value x0 and returns the approximated derivative f (x0 ) using CDD method. Modify function newton1 so that input df can be dropped.

Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

13

J.H. Mathews, K.D. Fink.(2004). Numerical Methods Using Matlab, 4th edition, Pearson Education Inc. T. Sauer (2014). Numerical Analysis, 2nd edition. Pearson Education.

MMA307 lecture 6: Nonlinear equations III

Newton-Raphson Method Newton-Raphson method-MATLAB Implementation Other topics to be covered on the whiteboard Homework 6

13

You might also like