36
MA2213 Lecture 1 Rootfindi ng

MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Embed Size (px)

Citation preview

Page 1: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

MA2213 Lecture 1

Rootfinding

Page 2: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Class ScheduleLectures:

Tuesday 2-4 in LT31 (building S16)

Groups: Class will be divided into 5 groups

Each group (of about 25 students) will:

Tutorials: will meet in weeks 3,5,7,9,11

Labs: will meet in weeks 4,6,8,10,12

do tutorials and labs together

Friday 2-4 in LT31 (building S16)

be assigned a person who will supervise both

tutorials and labs, and grade written homework

(more information will be announced soon)

Page 3: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

SuggestionsDo:

Attend lectures, tutorials, and labs

Complete assigned homework and give

to your grader during tutorials and labs

Do Not:

Send or give me assigned homework

Study the textbook and work problems

Use the Module IVLE Website

Email me questions whose answers

are on the Module IVLE Website

Purchase the required textbook

Page 4: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Objectives and PrerequisitesLearn Numerical Methods

Accuracy and Errors

Computer Algorithms (MATLAB)

CalculusReal Numbers and Complex NumbersFundamental Theorem of AlgebraFundamental Theorems of Calculus

Linear Equations: Geometry and Matrix Algebra

Vector Spaces and Linear Transformations

Linear Algebra

Prerequisites

Page 5: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Required Textbook

Elementary Numerical Methods by Atkinson and Han

About 20 books are now in the Science COOP(due to limited shelve space) but more bookswill be transferred from the warehouse)

Homework (Tutorial and Lab) may be assigned from this textbook

Suggested Reading from this textbookAppendix A&B Math Rev, D MATLAB

Page 6: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Lecture Schedule

1 Rootfinding 14, 17 Aug2 Interpolation 21, 24 Aug3 Approximation 28, 31 Aug4 Numerical Integration 4, 7 Sept5 Linear Equations (Direct) 11, 14 Sept 6 Linear Equations (Iterative) 18, 21 Sept

Recess Week 24-28 SeptReview and Midterm Test 2, 5 Oct

Lecture # Topic Dates

Page 7: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Lecture Schedule

7 Eigenvalues 9, 12 Oct 8 Nonlinear Systems 16, 19 Oct9 ODE (Explicit) 23, 26 Oct10 ODE (Implicit) 30 Oct, 2 Nov11 PDE 6, 9 Nov12  Review 13, 16 Nov

Lecture # Topic Dates

EXAM : Friday, 30 Nov 200(MORNING)

Page 8: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Planning (pages 71-72)

inPdeposited at beginning of each ofAmount

rinN time periods. Interest is paid per period.

End of Period Amount of Money in the Account

1 inPrA )1()1( inPrArA )1()1()1()2( 2inin PrPr )1()1( 2

1k inPrkArkA )1()()1()1(

Page 9: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Planning (pages 71-72)

Specifying and the value of

in terms of the value of suffices to write

a computer program to compute

)1(A

A

)1( kA)(kA

The figure shows thatif you deposited $1000 monthy at r = 0.0025you would have $584,194 after 30 years

Page 10: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Planning (pages 71-72)Here is the smallest MATLAB code required

function A = amount(Pin,Nin,r)A(1) = (1+r)*Pin;for k = 1:Nin-1 A(k+1) = (1+r)*A(k) + (1+r)*Pin;endyou would write and store it in a m-file amount.m and then run it interactively using the commands: A = amount(1000,360,0.0025)plot(A); grid; xlabel(‘End of Period (Month)’)ylabel(‘Amount at end of Period’)

Page 11: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Planning (pages 71-72)But your grader will demand documented codefunction A = amount(Pin,Nin,r)% function A = amount(Pin,Nin,r)% % Wayne Lawton, Student Number: XXXXXX% MA2213, Homework Assignment 1% Date: Tuesday 14 August 2007% % Computes Amount of Money in an Interest Bearing Account%% Inputs:% Pin = input at beginning of each period% Nin = number of input periods% r = interest earned during each period% Outputs:% A = array of length Nin% A(k) = amounts at the end of the k-th period%A(1) = (1+r)*Pin;for k = 1:Nin-1 A(k+1) = (1+r)*A(k) + (1+r)*Pin;end

Page 12: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Planning (pages 71-72)Comments (start with %) are useful in interactive mode

>> help amount

function A = amount(Pin,Nin,r) Wayne Lawton, Student Number: XXXXXX MA2213, Homework Assignment 1 Date: Tuesday 14 August 2007 Computes Amount of Money in an Interest Bearing Account Inputs: Pin = input at beginning of each period Nin = number of input periods r = interest earned during each period Outputs: A = array of length Nin A(k) = amounts at the end of the k-th period

Page 13: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Planning (pages 71-72)

An algebraic calculation gives

We now derive a closed expression for

Case 1.

ininN PrPr in )1()1( 1

ininin PNSr 0

ininN

inN PrPrPr inin )1()1()1( 1

)( inin NAS

inS

Case 2. inin SrSrr ]1)1[(0

in

N

in Pr

rrS

in )1()1( 1

Page 14: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Planning (pages 71-72)

At the end of period

we withdraw the first of payments each ofoutNinN

to leave 0 after the last withdrawal.

,beginning of period 1inN

outPamount Withdrawal #

1Amount After Withdrawal

outin PSA )1(

1k outPkArkA )()1()1(

2outoutin PPSrA ))(1()2(

outN )()1()( 1outin

Nout PSrNA out

outoutoutN PPrPr out )1()1( 2

3 outoutoutin PPrPSrA )1()()1()3( 2

Page 15: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Planning (pages 71-72)

Therefore, the method for geometric series gives

substituting for

outN

inN

out PrSrNA outout ]1)1[()1()( 11

out

N

inN

out Pr

rSrNAr

out

out1)1(

)1()(1 1

inS then gives

outN

inNN PrPrrr outinout ]1)1[()]1()1[()1( 11

)( outNAr

therefore if 1r and

0)( outNA then r1

is a root of the retirement polynomial

outN

outinNN

in PxPPxPxR outoutin )()(

outoutininoutoutinout PNPNPNSNAr )(1

Page 16: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Polynomial

If thenNNN outin is a root of Nr)1(

therefore, the quadratic formula gives

inoutinoutinoutin PPPPPPP 2/4)( 2

since .1

the polynomial

outN

outinNN

in PxPPxPxR outoutin )()(

outoutinin PxPPxP )(2

in

outininoutoutin P

PPPPPP 2/||

Page 17: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement Polynomial

Result: If

0r

then there exists so that

is a root of the retirement poly

We first factorize

outN

outinNN

in PxPPxPxR outoutin )()(

0 outoutinin PNPN

r1

)()1()( xQxxR

)1()( 1 xxxPxQ inout NNin

)1( 1 xxP outNout

Then we observe that 0)1( outoutinin PNPNQ

and 0)( inNinoutin PPPQ

Page 18: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Retirement PolynomialExample What is the minimal monthly interest rate to support the following retirement dream

then

4000,240,1000,360 outoutinin PNPN0045.1)( inN

inoutin PPP

Page 19: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Ancient Rootfinding

• Problem : Given a function f(x), find x* such that f(x*) = 0. Example. Compute

2)(f 2 xxThe Babylonian clay tablet YBC 7289 (c. 2000–1650 BC) gives an approximation of x* = in four sexagesimal figures, which is about six decimal figures                                                         

• Example :

2

Page 20: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Bisection Method (pages 72-79)Theorem: If f(x) is continuous in the interval [a,b]and , then there exists such that f(x*) = 0. Hence

2

bam

a b

)(f a

)(f b

midpoint

x

y

)(f xy

there exists a x* in (a,m) such that f(x*) = 0

Observation: If

0)(f)(f ba

0)(f)(f mathen (1)or (2)or (3)

0)(f)(f bm

(2)

(1)

there exists a x* in (m,b) such that f(x*) = 0

0)(f)(f ba),[],( bmxormax

),( bax

0)(f m

(3) a root is found

Page 21: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Bisection Method (pages 72-79)If nathen compute sequence0)(f)(f ba

For k = 2:N

2/)(,, 11111 bambbaa

0)(f)(f 11 kk maIf

else 2,, 11

kkkkkkk

bammbaa

2,, 11

kkkkkkk

bambbma

Nmx *

Page 22: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Bisection Method (pages 72-79)At the algorithm executes the “k = N” instructionit computes

)(2||2|| 1* ababrx NNN

Therefore, the computed root Nmx *

],[],,[ babbaa NN there exists

such that

],[ NN bar such that .0)(f rsatisfies

Question: How large should N be chosen to be ?

Question: How large will the residual |f(x*)| be ?

Page 23: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Bisection Method (pages 72-79)Find root of

5.1,2,1 111 mba025.0)(f)(f 11 ma

25.1,5.1,1 222 mba

3750.1,5.1,25.1 333 mba

2)(f 2 xx ]2,1[in the interval

04375.0)(f)(f 22 ma

00820.0)(f)(f 33 ma4375.1,5.1,3750.1 444 mba

4375.1x 0664.0)(f x

Page 24: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Questions for Thought and Discussion

What are advantages of the bisection method?

What are disadvantages of the bisection method?

How could the bisection method be used to compute 1/y on a computer that could only add, subtract, and multiply ?

Page 25: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Newton’s Method (pages 79-89)

Question: How should we compute

2xx

)(f

)(xf

1'

112 xxx

x

y )(f xy

1x

Observation: Clearly |||| 12 xxxx

3x ?

Question: What happens if f(x) = ax + b ?

Page 26: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Newton’s Method (pages 79-89)

Question: How should we compute

)(f

)(xf

1'

112 xxx

3x ?

)(f

)(xf

2'

223 xxx

1,)(f

)(xf'

n1 n

xxx

nnn

We see a GENERAL PATTERN

Page 27: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Newton’s Method (pages 79-89)

Question: What happens if f(x) = ax + b ?

a

b

a

bx

xxx n

nnn

n'

n1

ax

)(f

)(xf

for ANY starting value for1x

a

b

a

bx

xxx

1

11

'1

12

ax

)(f

)(xf

332 xxxa

b

Page 28: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Newton’s Method (pages 79-89)Find root of

11 x

n

nnn x

xxx

2

22

1

1,2)(f 12 xxx

Solution: The iteration is

5.12

2112

x

4167.15.12

25.15.1

2

3

x

nn xxe 4142.12 x

4142.01 e

0858.02 e

0025.03 e

74514142156862.14 x 000002123.04 e

Page 29: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Newton’s Method (pages 79-89)Find root of )2(1 nnn xbxx ,)(f 1 xbx

11 20 bx

1b

Question Why should ?

Question When would this algorithm be useful ?

12 b

by

x

y)(f xy

)(f xy

Page 30: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Taylor’s Polynomial (pages 2-11)Definition If derivatives on

is called the degree n Taylor Polynomial of f at a.

has

then the polynomialf

nn axaaxaaxaa ))((f))((f))((f)(f (n)!

12''21'

Example

)(xPn

2''21' ))((f))((f)2(f axaaxa

n and],[ ],[ a

],[,1)(f 3 xxxthe degree 2 Taylor Polynomial at 2 is )(2 xP

2)2(6)2(129 xx

9126 2 xx

Page 31: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Taylor’s Polynomial (pages 2-11)

BLUE 1+x^3 GREEN Taylor Polynomial

Page 32: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Error in Taylor Polynomial (pages 11-23)

Theorem If an interval

has n+1 continuous derivatives onf

fdegree n Taylor Polynomial for

and andnP|,[

at then

}],max{},,[min{)( xaxaxc

is the

)()(f)( xPxxR nn

|,[ aa

Taylor’s Remainder satisfies

],[)),((f)()( 1)(n1)!1(

1 xxcaxxR nnn

where

(this means that c(x) is between a and x)

Proof This very important result is proved in most Calculus textbooks, e.g. pages 1166-1167 inThomas’ CALCULUS, Tenth International Edition

Page 33: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Error Analysis (pages 83-86)Theorem Assume that

derivatives on an intervalhas 2 continuousf

1xNewton’s algorithm starting

at

and LB < 2 where0)(f x

}:|(x)fmin{|2

}:|(x)f|max{'

''

Ix

IxB

|/,[ 22LL xxI

and

whose error

nn xxe gives a sequence

|||||| 22

1 nLB

nn eeBe

Ix 1Then for every

and 0)(f ' x for every Ix

Ixn sequence satisfies

and thereforenx converges to *x

Page 34: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Error Analysis (pages 83-86)

Newton’s Method gives )(f/)(xf 'n1 nnn xxx

2"

' )(2

)(f))((f)(f)(f0 nnnn xxxxxxx

nxatthen the degree 2

f],[x 2

*2

*n

LL xx Proof If

Taylor Polynomial for satisfies

where }],max{},,[min{ ** xxxx nn

therefore the errors satisfy

11 nn xxe

hence

)(f/)](f))((f[)(f/)(f '''*nnnnnnn xxxxxxxxx

2'''2*''' )](f2/)(f[))]((f2/)(f[ nnnn exxxx |||||| 2

21 nn

BLnn eeeBe complete the proof!

Page 35: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Questions for Thought and Discussion

What are advantages of Newton’s method?

How can the Bisection Method and Newton’s Method be combined to produce a method that has advantages of both ?

What are disadvantages of Newton’s method?

Page 36: MA2213 Lecture 1 Rootfinding. Class Schedule Lectures: Tuesday 2-4 in LT31 (building S16) Groups:Class will be divided into 5 groups Each group (of about

Homework Due Tutorial 1Question 1. Solve problem 1. a. on page 77

Question 2. Find the real root of the polynomial (in the previous question) using Newton’s method

Suggested Reading: pages 71-89,Appendix A. Mean Value TheoremsAppendix D. MATLAB: An Introduction

Discuss with your tutor the “Questions for Thought and Discussion”

||ln2ln||ln 1 nn eBe

Extra Credit Use the following formula

to derive a ‘closed form’ upper bound for || ne