Вы находитесь на странице: 1из 23

Lecture 2: Introduction to

Ordinary Differential Equation


(ODE) and Euler Method
KKEK214:2 Numerical Methods for Engineers 2
Department of Chemical Engineering

Differential Equation
Definition:
a
mathematical
equation that consists of an
unknown
function
and
its
derivatives.
It expresses the relation between a
function and its derivatives.
Differential equations play a
fundamental role in engineering
because many physical phenomena
are
best
formulated
mathematically in terms of their
rate of change.
Examples: reaction rate, mass flow,
heat transfer rate, acceleration,
velocity, etc.

E.g.: Newtons Second Law

dv
c
g v
dt
m
(1)
Where:
= velocity
g = gravitational constant
t = time
m = mass
c = drag coefficient
- dependent variable

t- independent variable
2
MDH-KKEK2142 (Sem 2 2014/2015)

Differential Equation
When a function involves one independent variable, the
equation is called an ordinary differential equation (or ODE).
A partial differential equation (or PDE) involves two or more
independent variables.

3
MDH-KKEK2142 (Sem 2 2014/2015)

Example: ODE in chemical reaction problem


A chemical reaction of the type of
k1

A BC
k2

(2)

takes place in a reactor, the


material balance can be applied as:

Input

+ Generation

Output +
Accumulation

Hence,

dC A
k1C AC B k 2CC
dt
dC B
k1C AC B k 2CC
dt
dCC
k1C AC B k 2CC
dt

ODE

(3)

For a batch reactor,


Input
+ Generation

Output +
Accumulation

MDH-KKEK2142 (Sem 2 2014/2015)

Classification of ODEs
ODEs are classified according to their order and their linearity.
The order of an ODE is the order of the highest derivative present in
that equation.
1st order
2nd order

dy
y kx
dx
d2y
dy
y
kx
2
dx
dx

3rd order

d y
d y dy
a 2 b kx
3
dx
dx
dx
3

MDH-KKEK2142 (Sem 2 2014/2015)

Classification of ODEs
ODEs also can be classified according to its linearity, i.e. linear
and nonlinear ODE.
An ODE is nonlinear if it contains product of the dependent
variable or its derivatives or both.
Linear
Nonlinear

dy
y kx
dx
d2y
dy
y
kx
2
dx
dx

Nonlinear

d y
d y
dy
a 2 b kx
3
dx
dx
dx
3

MDH-KKEK2142 (Sem 2 2014/2015)

Degree of ODEs
The degree of an ODE is the largest power to which the highest
order derivative is raised.

d y
d y dy
3 a 2 b kx
dx
dx
dx
3

d y
d y
dy
3 a 2 b kx
dx
dx
dx
3

Has degree of 5

10

Has degree of 2

7
MDH-KKEK2142 (Sem 2 2014/2015)

Runge-Kutta Methods
However not all ODEs can be solved using analytical
methods of calculus.
Need to use numerical methods.
Methods used to solve ODEs using iterative
methods.
Developed by German mathematicians C. Runge and
M.W. Kutta.

dy
f ( x, y )
dx
8
MDH-KKEK2142 (Sem 2 2014/2015)

Runge-Kutta Methods
Eulers method
Heuns method
Midpoint method
Higher Order Runge-Kutta (RK) method

MDH-KKEK2142 (Sem 2 2014/2015)

Runge-Kutta Methods
Solve ordinary differential equations of the form
dy
f ( x, y )
dx

Numerical method in the general form of


= +
or in mathematical terms
+1 = +
Applied step by step to compute out the value in the future
(trajectory of the solution).

MDH-KKEK2142 (Sem 2 2014/2015)

10

Runge-Kutta Methods
The type of RK methods can be differentiated by the manner in
which the slope is estimated.
The easiest one-step method: Eulers method.
However, Eulers method has the least accurate predictions
compared to other RK methods.

MDH-KKEK2142 (Sem 2 2014/2015)

11

Eulers Method
Named after Leonhard Euler (1707-1783).
Swiss mathematician and physicist.
He introduced several mathematical notations
such as f(x), e (also known as Eulers number),
for summation and i.
He also had introduce the Eulers method to
solve ordinary differential equation.
It is the simplest method to solve an ODE with
a given initial value, yo.

MDH-KKEK2142 (Sem 2 2014/2015)

12

Eulers Method
The first derivative provides a direct
estimate of the slope at xi

f ( xi , yi )
where f(xi,yi) is the differential
equation evaluated at xi and yi. This
estimate can be substituted into the
equation:

yi 1 yi f ( xi , yi )h
A new value of y is predicted using
the slope to extrapolate linearly over
the step size h.

Figure 25.2 Eulers method

13
MDH-KKEK2142 (Sem 2 2014/2015)

Example (pg. 708 in Text Book):


Use Eulers method to numerically integrate
dy
2 x 3 12 x 2 20 x 8.5
dx

From x=0 to x=4 with a step size of 0.5. The initial


condition at x=0 is y=1.

MDH-KKEK2142 (Sem 2 2014/2015)

14

Exercise (homework)
Calculate the values from previous example for the subsequent steps, i.e.
y(1.0), y(1.5), y(2.0), y(2.5), y(3.0), y(3.5) and y(4.0).
Compare the value that you obtained using Eulers method with those
obtained using exact solution of

= 0.5 4 + 4 3 10 2 + 8.5 + 1

MDH-KKEK2142 (Sem 2 2014/2015)

15

Error Analysis of the RK Method


Numerical solutions of ODEs involves two types of
error:
i) Truncation/discretisation errors
Caused by the nature of the techniques employed to
approximate the value of y.
ii) Round off errors
Caused by the limited numbers of significant digits
MDH-KKEK2142 (Sem 2 2014/2015)

16

Error Analysis of the RK Method


Truncation errors:
i)

Local truncation error that results from an application of the method in


question over single step.

ii)

Propagated truncation error that results from the approximation


produced during the previous steps.

MDH-KKEK2142 (Sem 2 2014/2015)

17

Error Analysis of the Eulers Method (Cont.)


Total error = Local truncation error + Propagated truncation error

Global truncation error

MDH-KKEK2142 (Sem 2 2014/2015)

18

Error Analysis of the RK Method (Cont.)


Conclusions:
i)

The global error can be reduced by decreasing h.

ii)

The method will provide error-free predictions if the


underlying function is linear.

MDH-KKEK2142 (Sem 2 2014/2015)

19

MATLAB
Short for MATrix LABoratory

Advantages:

Optimized to perform engineering


and scientific calculations.
Initially designed to perform
matrix mathematics
Provides a very extensive library
of predefined functions to make
technical programming tasks
easier and more efficient.

1.

Ease of use

2.

Platform independence

3.

Pre-defined functions

4.

Device-independent plotting

5.

Graphical User Interface

6.

MATLAB Compiler

Disadvantages:
1.

Interpreted language
execute more slowly

2.

Cost

MDH-KKEK2142 (Sem 2 2014/2015)

20

MATLAB Environment: MATLAB Desktop

The Command Window:


User can enter interactive commands at the
command prompt (>>) and it will be executed on
the spot.
It is easier to use script files / M-files

MDH-KKEK2142 (Sem 2 2014/2015)

The MATLAB
Workspace
Stores the
variable name
and value
The Command
History Window
Displays the
commands that
user has entered

21

Getting Help
Help Browser

Other Important Functions

Type help on the command


window

Type demo to run MATLABs built-in


demonstrations.

Using lookfor command

clc : clear the Command Windows


content.
clear : clear the variables in the
Workspace
abort command by typing control-c

MDH-KKEK2142 (Sem 2 2014/2015)

22

Important Programming Pitfalls


Never use a variable with the same name as a MATLAB function or
command. If you do so, that function or command will become inaccessible.
If there is more than one function or command with the same name, the
first one found on the search path will be executed.
Never create an M-file with the same name as a MATLAB function or
command.

MDH-KKEK2142 (Sem 2 2014/2015)

23

Вам также может понравиться