You are on page 1of 12

2/22/16

ORDINARY DIFFERENTIAL EQUATIONS


INITIAL VALUE PROBLEMS
Lec. 7.1: Introduction and Eulers Methods
Dr. Niket Kaisare
Department of Chemical Engineering
IITMadras

NPTEL Course: MATLAB Programming for Numerical Computations Week-7

Introduction: ODE IVP


!" % &, ( is slope of ( vs. & curve
Given: = % &,(
!# y
and initial condition: ( & ) = () %(&, ()

Aim is to find: ( &*

Discussion and theory for numerical ODE-IVP:


Computational Techniques, Module-7 (http://nptel.ac.in/courses/103106074/25)

1
2/22/16

Introduction: ODE IVP


!" % &, ( is slope of ( vs. & curve
Given: = % &,(
!# y
and initial condition: ( & ) = () %(&, ()

(*./ (*
lim = % &, (
5)
t
(*./ = (** + -
%(&,
* ()
Numerical methods for ODE-IVP:
Use best estimate of slope - to obtain ( &

Example

ODEIVP:

ODE: ( 8 = 2&(
Initial: ( 0 =1

Analytical solution: ( & = exp & ?

Eulers Explicit Method:


(*./ = (* + % & * ,(*

2
2/22/16

Eulers Implicit Method

(*./ = (* + % & *./ ,(*./

Thus, use nonlinear solver (such as fsolve) to solve:


(*./ % & *./ ,(*./ (* = 0

@((*./)

Unlike explicit method, Eulers implicit method is globally stable


Computational Techniques, Module-7 Part-5 (http://nptel.ac.in/courses/103106074/29)

End of Lecture 7.1

3
2/22/16

ORDINARY DIFFERENTIAL EQUATIONS


INITIAL VALUE PROBLEMS
Lec. 7.2: Runge-Kutta (RK-2) Methods
Dr. Niket Kaisare
Department of Chemical Engineering
IITMadras

NPTEL Course: MATLAB Programming for Numerical Computations Week-7

Runge-Kutta Family of Methods


Eulers Explicit Method:
(*./ = (* + @*

Runge-Kutta Method:
(*./ = (* + -*
where, nth-order RK method gives slope as:
-* = A/ B/ + A? B? + + AD BD

See: Computational Techniques, Module-7 Part-2 (http://nptel.ac.in/courses/103106074/26)

4
2/22/16

Second-Order (RK-2) Methods

Heuns Method
5
(*./ = (* + ? B/ + B?
B/ = @ & * ,(* , B? = @ & * + , (* + B/

Midpoint Method
(*./ = (* + B?
5 5EF
B/ = @ & * ,(* , B? = @ & * + ? , (* + ?
etc.

End of Lecture 7.2

5
2/22/16

ORDINARY DIFFERENTIAL EQUATIONS


INITIAL VALUE PROBLEMS
Lec. 7.3: MATLAB ode45 Algorithm
Dr. Niket Kaisare
Department of Chemical Engineering
IITMadras

NPTEL Course: MATLAB Programming for Numerical Computations Week-7

Syntax of ode45

Typical use of ode45:


[tSol,ySol] = ode45(@(t,y) fName(t,y), [t0, tEnd], y0);
tSol, ySol: Solution vectors; MATLAB returns ySol for each time tSol
fName : Function that returns G( = % &, (
t0, y0 : Initial conditions representing ( &) = ()
tEnd : Final value until which the solution is desired

6
2/22/16

Example: Plug Flow Reactor

Concentration along a PFR is given by:


!H /
= ? J /.?L
!I
with J 0 = 1

Solve to find C for reactor volumes of 1, 5 and 10 liters

End of Lecture 7.3

7
2/22/16

ORDINARY DIFFERENTIAL EQUATIONS


INITIAL VALUE PROBLEMS
Lec. 7.4: Runge-Kutta Methods
Dr. Niket Kaisare
Department of Chemical Engineering
IITMadras

NPTEL Course: MATLAB Programming for Numerical Computations Week-7

Revisiting RK-2 Heuns Method

Generalize RK-2 Heuns Method to use function myFun(t,y)

Develop for ( 8 = 2&(


Extend to PFR problem

8
2/22/16

Higher Order Runge-Kutta Methods

RK-3 Method: (*./ = (* + A/ B/ + A? B? + AM BM

Can choose appropriate weights to have different orders of accuracy


Best local truncation error is N O

RK-4 is usually the most popular RK method, with error N L

Standard RK-4 method

5
(*./ = (* + B/ + 2B? + 2BM + BO + N L
P

B / = @ &*, (*
5 5EF
B ? = @ &* + ? , (* + ?

5 5EQ
B M = @ &* + ? , (* + ?

BO = @ &* + , (* + B M

9
2/22/16

End of Lecture 7.4

ORDINARY DIFFERENTIAL EQUATIONS


INITIAL VALUE PROBLEMS
Lec. 7.5: Error Analysis of Runge-Kutta Methods
Dr. Niket Kaisare
Department of Chemical Engineering
IITMadras

NPTEL Course: MATLAB Programming for Numerical Computations Week-7

10
2/22/16

Local Truncation Error

Eulers Method: (*./ = (* + %* + N ?

5
Heuns Method: (*./ = (* + ? B/ + B? + N M

5
RK-3 (Std.) Method: (*./ = (* + B/ + 4B? + BM + N O
P

5
RK-4 (Std.) Method: (*./ = (* + B/ + 2B? + 2BM + BO + N L
P

Global Truncation Error

Eulers Method GTE: N /

Heuns Method GTE: N ?

RK-3 Method GTE: N M

RK-4 Method GTE: N O

11
2/22/16

Local vs. Global Truncation Errors

GTE is one order lower than LTE

GTE for RK-2 gives the method as N ? accurate

Consider the previous example to demonstrate with Midpoint Rule

End of Lecture 7.5

12

You might also like