Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

Calculo Numérico II

IF-392

Semana 01
Dr. Pierre Giovanny Ramos Apestegui

Cálculo Numérico II-IF392


Cálculo Numérico II-IF392
Bibliography

Cálculo Numérico II-IF392


Introduction to Numerical Methods

• What are NUMERICAL METHODS?

• Why do we need them?

• Topics covered in this course

Cálculo Numérico II-IF392


Numerical Methods
NUMERICAL METHODS:
Algorithms that are used to obtain numerical solutions to a mathematical

problem.

WHY DO WE NEED IT?


• No analytical solution exists

• An analytical solution is difficult to obtain or not practical

Cálculo Numérico II-IF392


Outlines of the Course
Numerical Methods I Numerical Methods II
• Error, Taylor Theorem • Solution of ordinary
• Number Representation differential equations
• Solution of nonlinear (EDO)
Equations • Solution of Partial
• Solution of linear differential equations
Equations (EDP)
• Least Squares curve fitting
• Interpolation
• Numerical Differentiation
• Numerical Integration

Cálculo Numérico II-IF392


Contents

• Review to ODEs.
• Taylor series methods.

Cálculo Numérico II-IF392


Fast Review of ODEs
• Recall basic definitions of ODEs:
• Order
• Linearity
• Initial conditions
• Solutions of Ordinary Differential Equations.
• Classify ODEs based on:
• Order, linearity, and conditions.
• Classify the solution methods.

Cálculo Numérico II-IF392


Differential Equations
Differential
Equations

Ordinary Differential Equations Partial Differential Equations

d v2
u u 2 2

+ 6tv = 1 − 2 =0
dt 2 y 2
x
involve one or more involve one or more
Ordinary derivatives of partial derivatives of
unknown functions unknown functions

Cálculo Numérico II-IF392


Ordinary Differential Equations
Ordinary Differential Equations (ODEs) involve one or
more ordinary derivatives of unknown functions with
respect to one independent variable
Examples :
dv(t )
− v(t ) = e t x(t): unknown function
dt
d 2 x(t ) dx(t )
2
−5 + 2 x(t ) = cos(t )
dt dt
t: independent variable

Cálculo Numérico II-IF392


Example of ODE:
Model of Falling Parachutist
The velocity of a falling parachutist is
given by:

dv c
= 9.8 − v
dt M
M : mass
c : drag coefficient
v : velocity
Cálculo Numérico II-IF392
Definitions
Ordinary
differential
equation
dv c
= 9.8 − v
dt M

Cálculo Numérico II-IF392


Definitions (Cont.)

dv c
= 9.8 − v (Dependent
dt M variable)
unknown
function to be
determined

Cálculo Numérico II-IF392


Definitions (Cont.)

dv c
= 9.8 − v
dt M
(independent variable)
the variable with respect to which
other variables are differentiated

Cálculo Numérico II-IF392


Order of a Differential Equation
The order of an ordinary differential equation is the order of the
highest order derivative.

Examples :
dx(t )
− x(t ) = et First order ODE
dt
d 2 x(t ) dx(t )
2
−5 + 2 x(t ) = cos(t ) Second order ODE
dt dt
3
 d x(t )
2
 dx(t )
 2
 − + 2 x 4 (t ) = 1 Second order ODE
 dt  dt
Cálculo Numérico II-IF392
Linear ODE
An ODE is linear if The unknown function and its
derivatives appear to power one No product of the
unknown function and/or its derivatives
Examples :
dx(t )
− x(t ) = et
dt Linear ODE
d 2 x(t ) dx(t )
2
− 5 + 2t 2
x(t ) = cos(t ) Linear ODE
dt dt
3
 d x(t )  dx(t )
2
Non-linear ODE
 2
 − + x(t ) = 1
 dt  dt

Cálculo Numérico II-IF392


Nonlinear ODE
An ODE is Nonlinear if the unknown function and its
derivatives appear to power different of one or product
of the unknown function and/or its derivatives

Examples of nonlinear ODE :


dx(t )
− cos( x(t )) = 1
dt
d 2 x(t ) dx(t )
2
− 5 x(t ) = 2
dt dt
d 2 x(t ) dx(t )
2
− + x(t ) = 1
dt dt
Cálculo Numérico II-IF392
Solutions of Ordinary Differential
Equations
x(t ) = cos( 2t )
is a solution to the ODE
2
d x(t )
2
+ 4 x(t ) = 0
dt
Is it unique?
All functions of the form x(t ) = cos(2t + c)
(where c is a real constant) are solutions.
Cálculo Numérico II-IF392
Uniqueness of a Solution
In order to uniquely specify a solution to an nth order
differential equation we need n conditions.

d 2 x (t )
+ 4 x (t ) = 0 Second order ODE
dt 2
x ( 0) = a Two conditions are needed
x (0) = b to uniquely specify the
solution

Cálculo Numérico II-IF392


Auxiliary Conditions

Auxiliary Conditions

Initial Conditions Boundary Conditions

 All conditions are at one point • The conditions are not at one point
of the independent variable of the independent variable

Cálculo Numérico II-IF392


Boundary-Value and
Initial value Problems
Initial-Value Problems Boundary-Value Problems

 The auxiliary conditions are at • The auxiliary conditions are not at one
one point of the independent point of the independent variable
variable • More difficult to solve than initial
value problems

x + 2 x + x = e −2 t x + 2 x + x = e −2t


x(0) = 1, x (0) = 2.5 x(0) = 1, x(2) = 1.5
same different

Cálculo Numérico II-IF392


Classification of ODEs
ODEs can be classified in different ways:
• Order
• First order ODE
• Second order ODE
• Nth order ODE
• Linearity
• Linear ODE
• Nonlinear ODE
• Auxiliary conditions
• Initial value problems
• Boundary value problems

Cálculo Numérico II-IF392


Analytical Solutions
• Analytical Solutions to ODEs are available for
linear ODEs and special classes of nonlinear
differential equations.

Numerical Solutions
• Numerical methods are used to obtain a graph or a
table of the unknown function.
• Most of the Numerical methods used to solve ODEs
are based directly (or indirectly) on the truncated
Taylor series expansion.
Cálculo Numérico II-IF392
Classification of the Methods

Numerical Methods
for Solving ODE

Single-Step Methods Multiple-Step Methods

Estimates of the solution at a Estimates of the solution at a


particular step are entirely based on particular step are based on
information on more than one step
information on the previous step

Cálculo Numérico II-IF392


Taylor Series Methods

Cálculo Numérico II-IF392


Taylor Series Method
The problem to be solved is a first order ODE:

dy( x)
= f ( x, y ), y ( x0 ) = y0
dx
Estimates of the solution at different base points:

y ( x0 + h), y ( x0 + 2h), y ( x0 + 3h), ....


are computed using the truncated Taylor series
expansions.

Cálculo Numérico II-IF392


Taylor Series Expansion
Truncated Taylor Series Expansion
n
h k  d k y 

y ( x0 + h)  
k !  dx k

k =0
 x = x0 , y = y 0 

dy h2 d 2 y hn d n y
 y ( x0 ) + h + 2
+ ... +
dx x = x0 ,
y= y
2! dx x = x0 , n! dx n x = x0 ,
0 y = y0 y = y0

The nth order Taylor series method uses the nth order
Truncated Taylor series expansion.

Cálculo Numérico II-IF392


Euler Method
• First order Taylor series method is known as Euler
Method.

• Only the constant term and linear term are used in


the Euler method.

• The error due to the use of the truncated Taylor


series is of order O(h2).

Cálculo Numérico II-IF392


First Order Taylor Series Method
(Euler Method)

dy
y ( x0 + h) = y ( x0 ) + h + O(h 2 )
dx x = x0 ,
y = y0

Notation :
xn = x0 + nh, yn = y ( xn ),
dy
= f ( xi , yi )
dx x = xi ,
y = yi

Euler Method
yi +1 = yi + h f ( xi , yi )

Cálculo Numérico II-IF392


Euler Method
Problem :
Given the first order ODE : y ( x) = f ( x, y )
with the initial condition : y0 = y ( x0 )
Determine : yi = y ( x0 + ih) for i = 1,2,...

Euler Method :
y0 = y ( x0 )
yi +1 = yi + h f ( xi , yi ) for i = 1,2,...

Cálculo Numérico II-IF392


Interpretation of Euler Method
y2

y1

y0

x0 x1 x2 x

Cálculo Numérico II-IF392


Interpretation of Euler Method

Slope=f(x0,y0)
y1
y1=y0+hf(x0,y0)
hf(x0,y0)
y0

x0 x1 x2 x
h

Cálculo Numérico II-IF392


Interpretation of Euler Method
y2 y2=y1+hf(x1,y1)
Slope=f(x1,y1)
hf(x1,y1)
Slope=f(x0,y0)
y1 y1=y0+hf(x0,y0)
hf(x0,y0)
y0

x0 x1 x2 x
h h

Cálculo Numérico II-IF392


Example 1
Use Euler method to solve the ODE:

dy
= 1+ x ,
2
y (1) = −4
dx
to determine y(1.01), y(1.02) and y(1.03).

Cálculo Numérico II-IF392


Example 1
f ( x, y ) = 1 + x , 2
x0 = 1, y0 = −4 , h = 0.01
Euler Method
yi +1 = yi + h f ( xi , yi )

Step1 : y1 = y0 + h f ( x0 , y0 ) = −4 + 0.01(1 + (1) 2 ) = −3.98


(
Step2 : y2 = y1 + h f ( x1 , y1 ) = −3.98 + 0.01 1 + (1.01) = −3.9598
2
)
Step3 : (
y3 = y2 + h f ( x2 , y2 ) = −3.9598 + 0.01 1 + (1.02) = −3.9394
2
)

Cálculo Numérico II-IF392


Example 1
f ( x, y ) = 1 + x ,
2
x0 = 1, y0 = −4 , h = 0.01
Summary of the result:
i xi yi
0 1.00 -4.00
1 1.01 -3.98
2 1.02 -3.9595
3 1.03 -3.9394

Cálculo Numérico II-IF392


Example 1
f ( x, y ) = 1 + x ,
2
x0 = 1, y0 = −4 , h = 0.01
Comparison with true value:
i xi yi True value of yi
0 1.00 -4.00 -4.00
1 1.01 -3.98 -3.97990
2 1.02 -3.9595 -3.95959
3 1.03 -3.9394 -3.93909

Cálculo Numérico II-IF392


Error Analysis for Euler’s Method
• Numerical solutions of ODEs involves two types of error:
• Truncation error
• Local truncation error
• Propagated truncation error
The sum of the two is the total or global truncation error
• Round-off errors (due to limited digits in representing numbers in a computer)

• We can use Taylor series to quantify the local truncation error in Euler’s method.

Given y' = f ( x , y ) f ( xi , yi ) 2
yi" 2 yi( n ) n Ea = h + R3
yi +1 = yi + y h +
'
i h + ... + h + Rn 2!
2! n!
f ( n−1) ( x i , yi ) n
f ( xi , yi ) 2
yi +1 = yi + f ( x i , yi )h +
f ' ( x i , yi ) 2
h + ... + h + O( hn+1 ) Ea  h = O(h 2 )
2! n! 2!
EULER Local Truncation ERROR

• The error is reduced by 4 times if the step size is halved ➔ O(h2).


• In real problems, the derivatives used in the Taylor series are not easy to obtain.
• If the solution to the differential equation is linear, the method will provide error free
predictions (2nd derivative is zero for a straight line).
Cálculo Numérico II-IF392
Second Order Taylor Series Methods
dy ( x)
Given = f ( y, x), y ( x0 ) = y0
dx
Second order Taylor Series method
2 2
dy h d y
yi +1 = yi + h + 2
+ O(h )
3

dx 2! dx
2
d y
2
needs to be derived analytically.
dx
Cálculo Numérico II-IF392
Third Order Taylor Series Methods
dy ( x)
Given = f ( y, x), y ( x0 ) = y0
dx
Third order Taylor Series method
2 2 3 3
dy h d y h d y
yi +1 = yi + h + 2
+ 3
+ O(h )
4

dx 2! dx 3! dx
2 3
d y d y
2
and 3 need to be derived analytically.
dx dx
Cálculo Numérico II-IF392
High Order Taylor Series Methods
dy ( x)
Given = f ( y, x), y ( x0 ) = y0
dx
th
n order Taylor Series method
dy h 2 d 2 y hn d n y n +1
yi +1 = yi + h + 2
+ .... + n
+ O(h )
dx 2! dx n! dx
2 3 n
d y d y d y
2
, 3 ,....., n need to be derived analytically.
dx dx dx

Cálculo Numérico II-IF392


Higher Order Taylor Series Methods

• High order Taylor series methods are more accurate


than Euler method.

• But, the 2nd, 3rd, and higher order derivatives need


to be derived analytically which may not be easy.

Cálculo Numérico II-IF392


Errors Comparation

Graphical comparison of the errors of the Euler method and the Taylor method of
order 2. Cálculo Numérico II-IF392
Example 2
Second order Taylor Series Method

Use Second order Taylor Series method to solve :


dx
+ 2 x + t = 1, x(0) = 1,
2
use h = 0.01
dt

2
d x(t )
What is : 2
?
dt

Cálculo Numérico II-IF392


Example 2
Use Second order Taylor Series method to solve :
dx
+ 2 x + t = 1, x(0) = 1,
2
use h = 0.01
dt
dx
= 1 − 2x2 − t
dt
d 2 x(t ) dx
2
= 0 − 4 x − 1 = − 4 x (1 − 2 x 2
− t ) −1
dt dt
2
h
xi +1 = xi + h(1 − 2 xi − ti ) + ( − 1 − 4 xi (1 − 2 xi − ti ))
2 2

2
Cálculo Numérico II-IF392
Example 2
f (t , x) = 1 − 2 x 2 − t , t0 = 0, x0 = 1, h = 0.01
2
h
xi +1 = xi + h(1 − 2 xi − ti ) + ( − 1 − 4 xi (1 − 2 xi − ti ))
2 2

2
Step1 :

x1 = 1 + 0.01(1 − 2(1) 2
− 0) +
(0.01)
2
(−1 − 4(1)(1 − 2 − 0)) = 0.9901
2
Step 2 :

x2 = 0.9901 + 0.01(1 − 2(0.9901) 2


− 0.01) +
(0.01)
2
(−1 − 4(0.9901)(1 − 2(0.9901) 2 − 0.01)) = 0.9807
2
Step 3 :
x3 = 0.9716

Cálculo Numérico II-IF392


Example 2
f (t , x) = 1 − 2 x − t ,
2
t0 = 0, x0 = 1, h = 0.01
Summary of the results:
i ti xi
0 0.00 1
1 0.01 0.9901
2 0.02 0.9807
3 0.03 0.9716

Cálculo Numérico II-IF392


Exercise:

Using Matlab or Octave, compare the numerical solution


for different h=0.1 and h=0.05

Cálculo Numérico II-IF392

You might also like