Documente Academic
Documente Profesional
Documente Cultură
Topic 1:
Int d ti n to
Introduction t Numerical
N i l methods
th d and
nd Taylor
T l Series
S i
Lectures 1-4:
SE301_Topic1 1
Lecture 1
Introduction to Numerical Methods
SE301_Topic1 2
N
Numerical
ri l MMethods
th d
Numerical Methods:
Algorithms that are used to obtain numerical
solutions of a mathematical problem.
Why do we need them?
1 No analytical solution exists,
1. exists
2. An analytical solution is difficult to obtain
or not practical.
p
SE301_Topic1 3
Wh t ddo we need
What d
Basic Needs in the Numerical Methods:
Practical:
can be computed
p in a reasonable amount of time.
Accurate:
Good approximate to the true value
I f
Information
ti about
b t the
th approximation
i ti error
(Bounds, error order,… )
SE301_Topic1 4
O tli
Outlines off the
th Course
C r
Taylor
y Theorem Solution of linear
Number Representation Equations
Solution of nonlinear Least Squares curve
Equations fitti
fitting
Interpolation
Solution of ordinary
Numerical Differentiation
differential equations
Numerical Integration
Solution of Partial
differential equations
SE301_Topic1 5
S l ti n off N
Solution Nonlinear
nlin r Eq
Equations
ti n
Some simple equations can be solved analytically
x2 + 4x + 3 = 0
− 4 ± 4 2 − 4 (1 )( 3 )
Analytic solution roots =
2 (1 )
x = − 1 and x = −3
Many other equations have no analytical solution
x 9 − 2 x 2 + 5 = 0 ⎫⎪
−x ⎬ No
N analytic
l ti solution
l ti
x = e ⎪⎭
SE301_Topic1 6
Methods for solving Nonlinear
E
Equations
i
o Bisection Method
o Newton-Raphson Method
o Secant Method
SE301_Topic1 7
Solution of Systems of
Li r E
Linear Equations
ti
x1 + x 2 = 3
x1 + 2 x 2 = 5
We can solve it as
x1 = 3 − x 2 , 3 − x2 + 2 x2 = 5
⇒ x 2 = 2, x1 = 3 − 2 = 1
What to do if we have
1000 equations in 1000 unknowns
SE301_Topic1 8
Cr
Cramer’s
r’ RRule
l iis nott pr
practical
ti l
Cramer' s Rule can be used to solve the system
3 1 1 3
5 2 1 5
x1 = = 1, x2 = =2
1 1 1 1
1 2 1 2
SE301_Topic1 10
C r Fitti
Curve Fitting
Given a set of data
x 0 1 2
y 0.5 10.3 21.3
SE301_Topic1 11
I t rp l ti
Interpolation
Given a set of data
xi 0 1 2
yi 0.5 10.3 15.3
SE301_Topic1 13
I t r ti
Integration
Some functions can be integrated
analytically
3 3
1 2 9 1
∫ xdx = 2 x = 2 − 2 = 4
1 1
∫e
−x2
dx = ?
0
SE301_Topic1 14
M h d ffor N
Methods Numerical
i l IIntegration
i
o Upper and Lower Sums
o Trapezoid Method
o Romberg Method
o Gauss Quadrature
SE301_Topic1 15
Solution of Ordinary Differential Equations
A solution to the differential equation
x(t ) + 3 x (t ) + 3 x(t ) = 0
x (0) = 1; x(0) = 0
is a function x(t)
( ) that satisfies the equations
q
*A
Analytical
l ti l solutions
l ti are available
il bl for
f
special cases only
SE301_Topic1 16
Solution of Partial Differential
E ti
Equations
Partial Differential Equations are more
difficult to solve than ordinary differential
equations
∂ u2
∂ u
2
+ +2=0
∂x 2
∂t 2
i (πx)
u (0, t ) = u (1, t ) = 0, u ( x,0) = sin(
SE301_Topic1 17
S
Summary
r
Topics Covered in the Course
Numerical Methods:
Algorithms that are
Solution of nonlinear Equations
used to obtain Solution of linear Equations
numerical solution of a
Curve fitting
mathematical problem.
We need them when Least Squares
No analytical solution Interpolation
exist or it is difficult Numerical
N me ical Integration
Integ ation
to obtain.
Numerical Differentiation
Solution of ordinary differential
equations
Solution of Partial differential
q
equations
SE301_Topic1 18
Lecture 2
Number Representation and accurcy
Number Representation
Normalized Floating Point Representation
Significant Digits
Accuracy and Precision
Rounding and Chopping
± 3 1 2 . 4 5
sign integral fraction
part part
SE301_Topic1 20
Normalized Floating Point
R
Representation
i
Normalized Floating
g Point Representation
p
± 0. d1 d 2 d 3 d 4 × 10 n
sign
i mantissa
i exponent
d1 ≠ 0, n : integer
No integral part,
Advantage Efficient in representing very small or very large numbers
SE301_Topic1 21
C l l t rE
Calculator Example
pl
suppose you want to compute
3.578 * 2.139
using a calculator with two
two-digit
digit fractions
3 57
3.57 * 2 13 = 7
2.13 7.60
60
SE301_Topic1 22
Bi
Binary System
S
b1 ≠ 0 ⇒ b1 = 1
−1 −2 −3
(0.101) 2 = (1× 2 + 0 × 2 + 1× 2 )10 = (0.625)10
SE301_Topic1 23
7-Bit Representation
( i 1 bit,
(sign: bi MMantissa
i 3bits,exponent
3bi 3 bits)
bi )
SE301_Topic1 24
Fact
Number that have finite expansion
p in one numbering
g
system may have an infinite expansion in another
numbering system
(0.1)10 = (0.000110011001100...)) 2
You can never represent 0.1 exactly in any computer
SE301_Topic1 25
R
Representation
i
SE301_Topic1 26
1
08R
Representation
0.8 i
Gap near zero
0.6
0.4
0.2
-0
0.2
2
-0.4
-0.6
-0.8
-1
0 0.2
SE301_Topic1 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
27
R
Remarks
rk
SE301_Topic1 28
Si ifi t Di
Significant Digits
it
Significant
g digits
g are those digits
g that can be used with
confidence.
SE301_Topic1 29
48 9
48.9
SE301_Topic1 30
A r and
Accuracy d Pr
Precision
ii
SE301_Topic1 31
SE301_Topic1 32
R
Rounding
di andd Chopping
Ch ppi
SE301_Topic1 33
Fi 3.7
Fig 37
SE301_Topic1 34
Error Definitions
T Error
True E
SE301_Topic1 35
Error Definitions
Estimated error
SE301_Topic1 36
Notation
We say
y the estimate is correct to n decimal
digits if −n
Error ≤ 10
SE301_Topic1 37
S
Summary
r
Number Representation
Number that have finite expansion in one numbering system may
have an infinite expansion in another numbering system.
Normalized Floating Point Representation
Efficient in representing very small or very large numbers
Difference between machine numbers is not uniform
Representation error depends on the number of bits used in the
mantissa.
SE301_Topic1 38
Lectures 33-44
Taylor Theorem
Motivation
T l Th
Taylor Theorem
Examples
SE301_Topic1 40
T l r SSeries
Taylor ri
Th Taylor
The T l series i off f ( x) about
i expansion b t x0
f ( 2) ( x0 ) f (3) ( x0 )
f ( x0 ) + f ( x0 ) ( x − x0 ) +
'
( x − x0 ) +
2
( x − x0 )3 + ...
2! 3!
or
∞
1 (k )
Taylor Series = ∑ k! f ( x0 ) ( x − x0 ) k
k =0
if the series converge we can write
∞
f ( x) = ∑ k! f ( x0 ) ( x − x0 ) k
1 (k )
k =0
SE301_Topic1 41
Taylor Series
E
Example
l 1
E
Example
l 1
2.5
exp(x)
p( )
1+x+0.5x 2
2
1+x
1.5
1
1
0.5
0
-1
1 -0
0.8
8 -0
0.6
6 -0
0.4
4 -0
0.2
2 0 02
0.2 04
0.4 06
0.6 08
0.8 1
SE301_Topic1 43
Taylor Series
E
Example
l 2
f ( x) = sin(( x) f (0) = 0
f ' ( x) = cos( x) f ' (0) = 1
f ( 2) ( x) = − sin( x) f ( 2) (0) = 0
f (3) ( x) = − cos( x) f (3) (0) = −1
∞
f ( k ) ( x0 ) x 3
x 5
x 7
sin( x) = ∑ k!
( x − x0 ) k = x − +
3! 5! 7!
− + ....
k =0
The
h series f x <∞
i converges for
SE301_Topic1 44
4
3
x
0 sin(x)
-1
x-x 3/3!
-2
-3
-4
-4
4 -3
3 -2
2 -1
1 0 1 2 3 4
SE301_Topic1 45
Convergence of Taylor Series
(Observations, Example 1)
The Taylor
Th T l seriesi converges fast f (few
(f terms
are needed) when x is near the point of
expansion.
p If ||x-c|| is large
g then more terms
are needed to get good approximation.
SE301_Topic1 46
Taylor Series
E
Example
l 3
1
Obtain Taylor series expansion of f(x) = about x = 0
1− x
1
f ( x) = f (0) = 1
1− x
1
f ' ( x) = f ( 0) = 1
(1 − x )2
2
f ( 2 ) ( x) = f (0) = 2
(1 − x )3
6
f ( 3) ( x ) = f (0) = 6
(1 − x )4
1
Taylor Series Expansion of = 1 + x + x 2 + x 3 + ....
1− x
SE301_Topic1 47
Example 3
remarks
k
C
Can we apply
l Taylor
T l series
i for
f x>1??
1??
SE301_Topic1 48
T l r Th
Taylor Theorem
r
If a function f(x) posses continuous derivatives
of orders 1,2,..., (n + 1) in a closed interval [a, b]
then for any c ∈ [a, b] (
(n+1)
) terms Truncated
Taylor Series
n
f ( k ) (c )
f ( x) = ∑ k!
( x − c) k + En+1
k =0
Reminder
where
f ( n+1) (ξ )
En+1 = ( x − c) n+1 and ξ is between x and c.
(n + 1)!
(n
SE301_Topic1 49
Taylor Theorem
SE301_Topic1 50
Err r T
Error Term
r
T get an idea
To id about
b the
h approximat
i ion
i error
SE301_Topic1 51
Error Term for
E
Example
l 4
L f ( x) have
Let h continuous
ti d i ti s off
derivative
orders 1,2,...(n + 1) on an interval [a,b] ,
and x ∈ [a,b] and x + h ∈ [a,b] then
n
f ( k ) ( x) k
f ( x + h) = ∑ k!
h + En+1
k =0
( n +1)
(ξ ) n+1
f
En+1 = h where ξ is between x and x + h
(n + 1)!
SE301_Topic1 53
Taylor Theorem
Alternative forms
( n +1)
n
f ( k ) (c ) f (ξ )
f ( x) = ∑ k!
k
( x − c) +
(n + 1)!
( x − c) n+1
k =0
where ξ is between x and c
x → x + h, c → x
n
f ( k ) ( x) k f ( n+1) (ξ ) n+1
f ( x + h) = ∑ k!
h +
(n + 1)!
h
k =0
where
h ξ is
i between
b d x+h
x and
SE301_Topic1 54
M
Mean V
Value
l ThTheorem
r
If f(x)
f( ) is
i a continuous
ti f ti on a closed
function l d interval
i t l [a,
[ b]
and its derivative is defined on the open interval (a, b)
then there exist ξ ∈ [a, b]
df(ξ ) f(b) − f(a)
=
dx (b-a)
y Theorem n = 0, x = a, x + h = b
Proof : Use Taylor
df(ξ )
f(b) = f(a) + (b-a)
dx
SE301_Topic1 55
Alt r ti Series
Alternating S ri Th
Theorem
r
Consider the alternating series
S = a1 − a2 + a3 − a4 + "
⎧ a ≥ a ≥ a ≥ a ≥" ⎧The series converges
⎪⎪ 1 2 3 4
⎪
Iff ⎨ and then ⎨ and
⎪ lim a = 0 ⎪ S − S n ≤ an +1
⎪⎩ n→∞ n ⎩
S n : partial sum
s m (sum
(s m of the first n terms)
an +1 : First omitted term
SE301_Topic1 56
Alternating Series
E
Example
pl 5
1 1 1
sin(1) can be computed using sin(1) = 1 − + − + "
3! 5! 7!
This is a convergent alternating series since
a1 ≥ a2 ≥ a3 ≥ a4 ≥ " and lim an = 0
n →∞
Then
⎛ 1⎞ 1
sin(1) − ⎜1 − ≤
⎝ 3! ⎠ 5!
⎛ 1 1⎞ 1
sin(1) − ⎜1 − + ≤
⎝ 3! 5! ⎠ 7!
SE301_Topic1 57
E
Example
pl 6
Obtain the Taylor series expansion
of f(x) = e 2x +1 about c = 0.5 (the center of expansion)
How large can the error be when (n + 1) terms are used
to app ate e 2x +1 w
approximat
o t x = 1?
with
SE301_Topic1 58
E
Example
l 6
f ( k ) ( x) = 2 k e 2 x +1
f ( n+1) (ξ )
Error = ( x − 0.5) n+1
(n + 1)!
( x − 0.5) n+1
Error = 2 n+1 e 2ξ +1
(n + 1)!
( x − 0.5) n+1
Error ≤ 2 n +1
max e 2ξ +1
(n + 1)! ξ ∈[0.5,1]
n +1
( x − 0 . 5)
Error ≤ 2 n+1 e3
(n + 1)!
SE301_Topic1 60
R
Remark
rk
In this course all angles are assumed to
be in radian unless you are told otherwise
SE301_Topic1 61
M l ri series
Maclurine ri
Find Maclurine series expansion of cos (x)
SE301_Topic1 62
Taylor Series
E
Example
l 7
Obt i Maclurine
Obtain M l i series i off f ( x) = cos(( x)
i expansion
f ( x) = cos( x) f ( 0) = 1
f ' ( x) = − sin( x) f ' (0) = 0
f ( 2 ) ( x) = − cos( x) f ( 2 ) (0) = −1
f ( 3) ( x) = sin( x) f ( 3 ) ( 0) = 0
∞
f ( k ) ( 0) x x x
cos( x) = ∑
2 4 6
( x) k = 1 − + − + ....
k =0 k! 2! 4! 6!
The series converges for x < ∞
SE301_Topic1 63