Numerical Analysis/The Secant Method

From testwiki
Jump to navigation Jump to search

The Secant Method

The secant method is an algorithm used to approximate the roots of a given function f. The method is based on approximating f using secant lines.

The Algorithm

The secant method algorithm requires the selection of two initial approximations x 0 and x 1, which may or may not bracket the desired root, but which are chosen reasonably close to the exact root.

Secant Method Algorithm
Given f(x)=0:

Let x0 and x 1 be initial approximations.
Then
Template:Center topxn=xn1f(xn1)xn1xn2f(xn1)f(xn2) Template:Center bottom
where xn is a better approximation of the exact root, assuming convergence.

Repeat iterative step until either

  1. The total number of iterations N is met
  2. A sufficient degree of accuracy, ϵ, is achieved.

Order of Convergence

We would like to be able to find the order of convergence, p, for the secant method. Hence, we want to find some p so that |xn+1x|Cp|xnx| where C is a constant.

Given a function f, let x be such that f(x)=0 and let xn-1 and xn be approximations to x. Assume x is a simple root and f is twice continuously differentiable (from the assumptions leading to convergence noted on Wikipedia). Let the error at the nth step be denoted by en: en=xn-x. Then we have:

en+1=xn+1x=xnf(xn)xnxn1f(xn)f(xn1)x=(xn1x)f(xn)(xnx)f(xn1)f(xn)f(xn1)=en1f(xn)enf(xn1)f(xn)f(xn1)=enen1(f(xn)enf(xn1)en1f(xn)f(xn1)).

Since f(x)=0 and recalling that en=xn-x, we can rewrite the last line above as: Template:NumBlk

Next, let's just consider the numerator in (Template:EquationNote). Let F(ω)=f(ω)f(x)ωx where ω=...xn1,xn,xn+1,.... Thus Template:NumBlk

According to the Mean Value Theorem, on [xn-1,xn], there exists some ζn between xn-1 and xn such that F(ζn)=F(xn)F(xn1)xnxn1 Template:NumBlk

Now using a Taylor expansion of f(x) around ω, we have Template:NumBlk

Next, we can combine equations (Template:EquationNote), (Template:EquationNote), and (Template:EquationNote) to show that F(xn)F(xn1)=(xnxn1)2f(νn).

Returning to (Template:EquationNote), we now have: Template:NumBlk

Again applying the Mean Value Theorem, there exists some ξn in [xn-1,xn] such that f(ξn)=f(xn)f(xn1)xnxn1. Then (Template:EquationNote) becomes:

en+1=enen1f(νn)2f(ξn)enen1f(x)2f(x).

Next, recall that we have convergence of order p when limn|xn+1x||xnx|p=limn|en+1||en|p=μ for some constant μ>0. Our goal is to figure out what p is for the secant method.

Let Sn=|en+1||enp|
|en+1|=Sn|en|p=Sn(Sn1|en1p|)p=SnSn1p|en1|p2.

Then we have: |en+1||en||en1|=SnSn1p|en1|p2Sn1|en1|p|en1|=SnSn1p1|en1|p2p1.

We want limn(SnSn1p1|en1|p2p1)=μ, again where μ is some constant. Since Sn and Sn1p1 are constants and limnen=0 (assuming convergence) we must have p2p1=0. Thus p=1+521.618.[1]

A Numerical Example

The function f(x)=sinx+xex has a root between -3 and -4. Let's approximate this root accurate to four decimal places.

Let x0 = -3 and x1 = -4. Next, using our recurrence formula where
Template:Center topf(x0)=f(3)=sin(3)3e30.2905 Template:Center bottom
and Template:Center topf(x1)=f(4)=sin(4)4e40.6835,Template:Center bottom
we have: Template:Center topx2=x1f(x1)x1x0f(x1)f(x0)=4.6835(4+3.6835+.2905)3.2983.Template:Center bottom

In the next iteration, we use f(x1) = .6835 and f(x2) = .0342 and see that
Template:Center topx3=x2f(x2)x2x1f(x2)f(x1)=3.2983.0342(3.2983+4.0342.6835)3.2613.Template:Center bottom

Similarly, we can compute x4 and x5. These calculations have been organized in the table below:

i 0 1 2 3 4 5
xi -3 -4 -3.2983 -3.2613 -3.2665 -3.2665

Hence the iterative method converges to -3.2665 after 4 iterations.

Pseudo Code

Below is pseudo code that will perform iterations of the secant method on a given function f.

Input: x0 and x1
Set y0=f(x0) and y1=f(x1)
Do 
   x=x1-y1*(x1-x0)/(y1-y0)
   y=f(x)
   Set x0=x1 and x1=x
   Set y0=y1 and y1=y
Until |y1|<tol

Exercises

Exercise 1

Find an approximation to 5 correct to four decimal places using the secant method on f(x)=x25.

Exercise 2

Find a root of f(x)=x+ex by performing five iterations of the secant method beginning with x0 = -1 and x1 = 0.

Quiz

The following is a quiz covering information presented on the associated secant method page on Wikipedia as well as the current page.

<quiz display=simple> {True or False: The secant method converges faster than the bisection method. |type="()"} + TRUE. - FALSE.

{True or False: The secant method converges faster than Newton's method. |type="()"} - TRUE. + FALSE.


{Check all that apply: The secant method may be less computationally expensive than Newton's method because... |type="[]"} + Newton's method requires evaluating the given function f and its derivative f'. - The secant method requires evaluating the given function f and its derivative f'. - The secant method requires only one new function evaluation in each iteration. - Newton's method requires only one new function evaluation in each iteration.

{Given the function f(x)=x4x8, perform 1 iteration of the secant method starting with x0 = 1 and x1 = 2. Then x2 is equal to: |type="()"} - 1.2311 + 1.5714 - 1.6231 - 1.7312

</quiz>

References

Template:Reflist

Template:CourseCat