lecture 11

10
Lecture 11 Rootfinding – Newton’s and secant methods 1 Lecture 11 More root finding methods Newton’s method Very fast way to find roots Requires taking the derivative of f(x) Can be unstable if ‘unattended’ Secant method Similar to Newton’s method, but derivative is numerical not analytical

Upload: adonis

Post on 06-Jan-2016

40 views

Category:

Documents


0 download

DESCRIPTION

Lecture 11. More root finding methods Newton’s method Very fast way to find roots Requires taking the derivative of f(x) Can be unstable if ‘unattended’ Secant method Similar to Newton’s method, but derivative is numerical not analytical. Newton’s method. X old = 5.318 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 1

Lecture 11

More root finding methods Newton’s method

Very fast way to find roots Requires taking the derivative of f(x) Can be unstable if ‘unattended’

Secant method Similar to Newton’s method, but derivative is

numerical not analytical

Page 2: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 2

Newton’s method

-15

-10

-5

0

5

10

15

-10 -5 0 5 10

125.018.0)( 23 xxxxf

Page 3: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 3

-6

-4

-2

0

2

4

6

8

10

12

3 4 5 6 7

254.0)( 2 xx

dx

xdf125.018.0)( 23 xxxxf

xold

oldoldnew

dx

xdf

fxx

)(

xoldnewold

newold

dx

xdf

xx

ff

)(

Define slope:

Xold = 4 f(xold) = -3.48df/dx@ xold = 2.64

Xold = 5.318 f(xold) = 3.296df/dx@ xold =7.955

Xnew = 5.318

Xnew = 4.839

Page 4: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 4

Newton Method Calculations

xold f(xold) df/[email protected] -3.48 2.64 5.31818

5.31818 3.2967 7.95467 4.90375

4.90375 0.394565 6.08148 4.83887

4.83887 0.008993 5.805034.8373154.837315 0.0000051 5.798484.837315

254.0)( 2 xx

dx

xdf

125.018.0)( 23 xxxxfxold

oldoldnew

dx

xdf

fxx

)(

Page 5: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 5

Newton’s method

-15

-10

-5

0

5

10

15

-10 -5 0 5 10

Answer depends on where you start.

x init = 2.00x root= 0.456469steps = 3

x init = 4.00x root= 4.83731steps = 4

x init = -4.00x root= -2.51601steps = 4

Page 6: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 6

Function for Newton’s Method

newtonexample.cpp code can be found in the Examples page.

Page 7: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 7

-6

-4

-2

0

2

4

6

8

10

12

3 4 5 6 7

125.018.0)( 23 xxxxf

X0 = 4 f(x0) = -3.48

)()(

)()(

1

11

nn

nnnnn xfxf

xxxfxx

Secant method

X2 = 4.5210

X1 = 6 f(x1) = 9.88

X3 = 4.7303

x1 and x0 don’t have to bound solution

f(x2) = -1.6287

f(x3) = -0.5967

X4 = 4.8513

)(

)()(

)(

0)(

01

01

21

1

xx

xfxf

xx

xf

)()(

)()(

01

01112 xfxf

xxxfxx

X2

Page 8: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 8

125.018.0)( 23 xxxxf

)()(

)()(

1

11

nn

nnnnn xfxf

xxxfxx

n xn-1 xnf(xn-1) f(xn) xn+11 4.0000 -3.4800 6.0000 9.8800 4.52102 6.0000 9.8800 4.5210 -1.6287 4.7303

3 4.5210 -1.6287 4.7303 -0.5967 4.8513

4 4.7303 -0.5967 4.8513 -0.0815 4.8368

5 4.8513 -0.0815 4.8373 -.0032 4.8373

Secant method table

Page 9: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 9

Secant method function

secantexample.cpp code can be found in the Examples page.

Page 10: Lecture 11

Lecture 11 Rootfinding – Newton’s and secant methods 10

Comparing methods:Iterations required to reach a tolerance of 0.0001

Method Initial x x Root #Iterationssubstitution 4.0 4.8373 18

bisection 4.0, 6.0 4.8373 17

Newton’s 4.0 4.8373 4

Secant 4.0, 6.0 4.8373 5