Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
MA2213 Lecture 1
Rootfinding
Class Schedule
Lectures:
Tuesday 2-4 in LT31 (building S16)
Friday 2-4 in LT31 (building S16)
Groups: Class will be divided into 5 groups
Each group (of about 25 students) will:
do tutorials and labs together
be assigned a person who will supervise both
tutorials and labs, and grade written homework
Tutorials: will meet in weeks 3,5,7,9,11
Labs: will meet in weeks 4,6,8,10,12
(more information will be announced soon)
Suggestions
Do:
Use the Module IVLE Website
Attend lectures, tutorials, and labs
Purchase the required textbook
Study the textbook and work problems
Complete assigned homework and give
to your grader during tutorials and labs
Do Not:
Send or give me assigned homework
Email me questions whose answers
are on the Module IVLE Website
Objectives and Prerequisites
Learn
Numerical Methods
Accuracy and Errors
Computer Algorithms (MATLAB)
Prerequisites
Real Numbers and Complex Numbers
Calculus Fundamental Theorem of Algebra
Fundamental Theorems of Calculus
Linear Algebra
Linear Equations: Geometry and Matrix Algebra
Vector Spaces and Linear Transformations
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 books
will be transferred from the warehouse)
Homework (Tutorial and Lab) may
be assigned from this textbook
Suggested Reading from this textbook
Appendix A&B Math Rev, D MATLAB
Lecture Schedule
Lecture #
Topic
Dates
1
Rootfinding
14, 17 Aug
2
Interpolation
21, 24 Aug
3
Approximation
28, 31 Aug
4
Numerical Integration
4, 7 Sept
5
Linear Equations (Direct) 11, 14 Sept
6
Linear Equations (Iterative) 18, 21 Sept
Recess Week
24-28 Sept
Review and Midterm Test
2, 5 Oct
Lecture Schedule
Lecture # Topic
7
8
9
10
11
12
Eigenvalues
Nonlinear Systems
ODE (Explicit)
ODE (Implicit)
PDE
Review
Dates
9, 12 Oct
16, 19 Oct
23, 26 Oct
30 Oct, 2 Nov
6, 9 Nov
13, 16 Nov
EXAM : Friday, 30 Nov 200(MORNING)
Retirement Planning (pages 71-72)
Amount
Pin deposited at beginning of each of
Nin time periods. Interest r
End of Period
1
2
is paid per period.
Amount of Money in the Account
A(1) (1 r ) Pin
A(2) (1 r ) A(1) (1 r ) Pin
(1 r ) Pin (1 r ) Pin
2
k 1
A(k 1) (1 r ) A(k ) (1 r ) Pin
Retirement Planning (pages 71-72)
A(1) and the value of A( k 1)
in terms of the value of A(k ) suffices to write
Specifying
a computer program to compute
A
The figure shows that
if you deposited $1000
monthy at r = 0.0025
you would have
$584,194 after 30 years
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;
end
you 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’)
Retirement Planning (pages 71-72)
But your grader will demand documented code
function 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
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
Retirement Planning (pages 71-72)
An algebraic calculation gives
(1 r )
N in 1
Pin (1 r ) Pin
We now derive a closed expression for Sin
N in
Pin (1 r )
Sin A( N in )
r 0 Sin Nin Pin
Case 2. r 0 r Sin [(1 r ) 1] Sin
N in 1
(1 r )
Pin (1 r ) Pin
Case 1.
Sin
(1 r )
N in 1
r
(1 r )
Pin
Retirement Planning (pages 71-72)
At the end of period N in ,beginning of period Nin 1
we withdraw the first of N out payments each of
amount Pout to leave 0 after the last withdrawal.
Withdrawal #
Amount After Withdrawal
1
A(1) Sin Pout
2
A(2) (1 r )( Sin Pout ) Pout
2
A(3) (1 r ) ( Sin Pout ) (1 r ) Pout Pout
3
k 1
N out
A(k 1) (1 r ) A(k ) Pout
N out 1
A( N out ) (1 r )
( Sin Pout )
(1 r )
N out 2
Pout (1 r ) Pout Pout
Retirement Planning (pages 71-72)
Therefore, the method for geometric series gives
N out 1
N out 1
A( N out ) (1 r )
Sin [(1 r )
1] Pout
r 1 A( N out ) Sin Nout Pout Nin Pin Nout Pout
N out
(1 r ) 1
N out 1
r 1 A( N out ) (1 r )
Sin
Pout
r
substituting for Sin then gives r A( N out )
(1 r )
N out 1
[(1 r )
N in 1
(1 r )]Pin [(1 r )
N out
1]Pout
therefore if r 1 and A( N out ) 0 then 1 r
is a root of the retirement polynomial
R( x) Pin x
N in N out
( Pin Pout ) x
N out
Pout
Retirement Polynomial
R( x) Pin x
N in N out
( Pin Pout ) x
If N in N out N then (1 r)
the polynomial
N
Pout
is a root of
Pin x ( Pin Pout ) x Pout
2
therefore, the quadratic formula gives
N out
Pin Pout ( Pin Pout ) 4Pin Pout / 2Pin
2
Pout since 1.
Pin Pout | Pout Pin | / 2 Pin
Pin
Retirement Polynomial
Result: If Nin Pin N out Pout 0 then there exists
r 0 so that 1 r is a root of the retirement poly
R( x) Pin x
N in N out
We first factorize
( Pin Pout ) x
R( x) ( x 1)Q( x)
N out
Pout
N in 1
Q( x) Pin x ( x
x 1)
N out 1
Pout ( x
x 1)
N out
Then we observe that Q(1) Nin Pin N out Pout 0
N in
Q
( Pin Pout ) Pin 0
and
Retirement Polynomial
Example What is the minimal monthly interest
rate to support the following retirement dream
Nin 360, Pin 1000, N out 240, Pout 4000
then
N in
( Pin Pout ) Pin 1.0045
Ancient Rootfinding
• Problem : Given a function f(x), find x*
such that f(x*) = 0. Example. Compute
• Example :
f ( x) x 2
2
The Babylonian clay tablet YBC 7289
(c. 2000–1650 BC) gives an
approximation of x* =
in four sexagesimal figures,
which is about six decimal
figures
2
Bisection Method (pages 72-79)
Theorem: If f(x) is continuous in the interval [a,b]
x
( a, b)
and f ( a )f (b) 0 , then there exists
such that f(x*) = 0. Hence x (a, m] or x [m, b)
Observation: If f ( a )f (b) 0
y
then (1) f (a) f (m) 0
y f ( x)
f (a)
or (2) f (m) f (b) 0
x
b
a
or (3) f ( m) 0
there exists a x* in (a,m)
(1)
such that f(x*) = 0
(2) there exists a x* in (m,b)
such that f(x*) = 0
(3) a root is found
f (b)
midpoint
ab
m
2
Bisection Method (pages 72-79)
If f ( a )f (b) 0 then compute sequence a n
a1 a, b1 b, m1 (a1 b1 ) / 2
For k = 2:N
If
f (ak 1 )f (mk 1 ) 0
ak bk
ak ak 1 , bk mk 1 , mk
2
else
ak bk
ak mk 1 , bk bk 1 , mk
2
*
x mN
Bisection Method (pages 72-79)
At the algorithm executes the “k = N” instruction
it computes a N [a, b], bN [a, b] such that
there exists
r [a N , bN ]
such that
Therefore, the computed root
1
x m N satisfies
*
| x r | 2 | bN a N | 2
*
f (r ) 0.
N
(b a )
Question: How large should N be chosen to be ?
Question: How large will the residual |f(x*)| be ?
Bisection Method (pages 72-79)
2
Find root of f ( x) x 2 in the interval [1, 2]
a1 1, b1 2, m1 1.5
f (a1 )f (m1 ) 0.25 0
a2 1, b2 1.5, m2 1.25
f (a2 )f (m2 ) 0.4375 0
a3 1.25, b3 1.5, m3 1.3750
f (a3 )f (m3 ) 0.0820 0
a4 1.3750, b4 1.5, m4 1.4375
f ( x ) 0.0664
x 1.4375
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 ?
Newton’s Method (pages 79-89)
y f ( x)
y
x
f (x 1 )
x2 x1 '
f ( x1 )
x
x2 x1
Observation: Clearly | x2 x | | x1 x |
Question: How should we compute x3 ?
Question: What happens if f(x) = ax + b ?
Newton’s Method (pages 79-89)
Question: How should we compute x3 ?
f (x 1 )
x2 x1 '
f ( x1 )
f (x 2 )
x3 x2 '
f ( x2 )
We see a GENERAL PATTERN
f (x n )
xn 1 xn '
, n 1
f ( xn )
Newton’s Method (pages 79-89)
Question: What happens if f(x) = ax + b ?
f (x n )
ax n b
b
xn 1 xn '
xn
f ( xn )
a
a
for ANY starting value for x1
f (x 1 )
ax1 b
b
x2 x1 '
x1
f ( x1 )
a
a
b
x2 x3 x3
a
Newton’s Method (pages 79-89)
Find root of f ( x) x 2,
2
x1 1
x 2
Solution: The iteration is xn 1 xn
2
x
n
x 2 1.4142 en x xn
x1 1
1 2
x2 1
1. 5
2
1.5 2
x3 1.5
1.4167
2 1.5
x4 1.41421568627451
2
2
n
e1 0.4142
e2 0.0858
e3 0.0025
e4 0.000002123
Newton’s Method (pages 79-89)
Find root of f ( x) b x 1 , xn 1 xn (2 b xn )
y f ( x)
y
yb
y f ( x)
x
b 1 2b 1
Question Why should
0 x1 2 b
1
?
Question When would this algorithm be useful ?
Taylor’s Polynomial (pages 2-11)
Definition If f has n derivatives on [ , ] and
a [ , ] then the polynomial Pn (x)
f (a) f (a)( x a) f (a)( x a) f (a)( x a)
'
1
2
''
2
1
n!
(n)
is called the degree n Taylor Polynomial of f at a.
Example f ( x) 1 x , x [, ]
the degree 2 Taylor Polynomial at 2 is P2 ( x)
3
f (2) f (a)( x a) f (a)( x a)
2
9 12( x 2) 6( x 2)
2
6 x 12 x 9
'
1
2
''
2
n
Taylor’s Polynomial (pages 2-11)
BLUE 1+x^3 GREEN Taylor Polynomial
Error in Taylor Polynomial (pages 11-23)
Theorem If f has n+1 continuous derivatives on
an interval [ , | and a [ , | and Pn is the
degree n Taylor Polynomial for f at a then
Taylor’s Remainder Rn ( x) f ( x) Pn ( x) satisfies
Rn ( x)
( x a) f
(c( x)), x [ , ]
where c( x) [min{ a, x}, max{ a, x}]
1
( n 1)!
n 1 (n 1)
(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 in
Thomas’ CALCULUS, Tenth International Edition
Error Analysis (pages 83-86)
Theorem Assume that f has 2 continuous
L
derivatives on an interval I [ x 2 /, x
'
and f ( x ) 0 and f ( x) 0 for every x I
and LB < 2 where
''
L
2
max{ | f (x) | : x I }
B
'
2 min{| f (x) | : x I }
|
Then for every x1 I Newton’s algorithm starting
at x1 gives a sequence xn I whose error
sequence en x xn satisfies
| en 1 | B | en |
2
LB
2
and therefore xn converges to x*
| en |
Error Analysis (pages 83-86)
Proof If x n [ x , x L2 ] then the degree 2
Taylor Polynomial for f at xn satisfies
*
*
L
2
f ( )
2
0 f ( x ) f ( xn ) f ( xn )( x xn )
( x xn )
2
*
*
where [min{ xn , x }, max{ xn , x }]
"
'
Newton’s Method gives xn 1 xn f (x n ) / f ( xn )
'
therefore the errors satisfy en 1 x xn 1
x xn f ( xn ) / f ( xn ) [f ( xn )( x xn ) f ( xn )] / f ( xn )
*
'
'
'
[f ( ) / 2f ( xn )]( x xn ) [f ( ) / 2f ( xn )] e
hence | en 1 | B en2 BL
complete the proof!
2 | en | | en |
''
'
*
2
''
'
2
n
Questions for Thought and Discussion
What are advantages of Newton’s method?
What are disadvantages of Newton’s method?
How can the Bisection Method and Newton’s
Method be combined to produce a method that
has advantages of both ?
Homework Due Tutorial 1
Question 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
Extra Credit Use the following formula
ln | en1 | ln B 2 ln | en |
to derive a ‘closed form’ upper bound for
| en |
Discuss with your tutor the
“Questions for Thought and Discussion”
Suggested Reading: pages 71-89,
Appendix A. Mean Value Theorems
Appendix D. MATLAB: An Introduction