0% found this document useful (0 votes)
23 views

TP3 2

This lab aims to numerically solve ordinary differential equations (ODEs) and systems of equations using the Euler method and Runge-Kutta method (RK4). Students are asked to: 1) Calculate exact solutions to four sample ODEs and systems of equations. 2) Write MATLAB programs to solve the given equations using Euler and RK4 with various step sizes. 3) Complete an error table comparing numerical solutions to exact solutions. 4) Plot exact and estimated solutions on the same graph. 5) Compare approximations to conclude on the accuracy and effectiveness of the two numerical methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

TP3 2

This lab aims to numerically solve ordinary differential equations (ODEs) and systems of equations using the Euler method and Runge-Kutta method (RK4). Students are asked to: 1) Calculate exact solutions to four sample ODEs and systems of equations. 2) Write MATLAB programs to solve the given equations using Euler and RK4 with various step sizes. 3) Complete an error table comparing numerical solutions to exact solutions. 4) Plot exact and estimated solutions on the same graph. 5) Compare approximations to conclude on the accuracy and effectiveness of the two numerical methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Mohamed El Bachir El Ibrahimi University -BBA- Master of Electrical Control (EC)

Science and Technology Faculty Lab: Applied Numerical Methods


Department of Electromechanics and Optimization

Lab 3: Solving Ordinary Differential Equations


(ODEs) and Systems of Equations
Objective: The aim of this lab is to numerically solve ordinary differential equations (ODEs) and systems of equations.
The considered equations are of the first and second order, linear or nonlinear, with initial conditions.

1. Brief Theory

1.1 Euler method

The Euler method is a straightforward numerical technique used to solve ODEs and systems of ODEs. It is based on
the idea of approximating the solution by incrementally stepping through the ODE using discrete time intervals.
Given a first-order ODE in the form:

dy
dt = f (t, y), with the initial condition y(t0 ) = y0 .

The Euler method updates the solution at each time step tn using the formula:

yn+1 = yn + h . f (tn , yn )

The computation is performed in the interval [t0 , tf ] with a calculation step size of h, and tn+1 = tn + h.


 dx

 = xn + h . f1 (tn , xn , yn , zn )

 dt

dy
For a system of two differential equations: = yn + h . f2 (tn , xn , yn , zn )

 dt



 dz = z + h . f (t , x , y , z )
n 3 n n n n
dt
The Euler method demonstrates local error proportional to the square of the step size (O(h 2 )), while its global error
is proportional to the step size (O(h)). This method serves as a foundational approach upon which more sophisticated
numerical techniques are built.

1.1 Runge-Kutta method

The Runge-Kutta (RK4) method is a numerical technique commonly used to solve ODEs. RK4 is a fourth-order method,
which means that its local error is on the order of O(h5 ) and the global error is on the order of O(h4 ), where h is the
step size. Here’s a brief overview of the RK4 method:
dy
The general form of a first-order ODE is given by: dt = f (t, y),
The RK4 method is an iterative procedure that updates the solution at each time step t n to obtain yn+1 .
The update formula for RK4 is as follows:

k1 = h . f (tn , yn )
h k1
k2 = h . f (tn + , yn + )
2 2
h k2
k3 = h . f (tn + , yn + )
2 2
k4 = h . f (tn + h, yn + k3 )
1
yn+1 = (k1 + 2k2 + 2k3 + k4 )
6

Dr. Dounia MERADI 9 2023-2024


Mohamed El Bachir El Ibrahimi University -BBA- Master of Electrical Control (EC)
Science and Technology Faculty Lab: Applied Numerical Methods
Department of Electromechanics and Optimization

2. Required work

To be solved:
dy
• The ODE 1: dt + 2y = 2 − e−4t , on the interval [0, 0.5] with y(0) = 1;
dy t t
• The ODE 2: dt − y = − 12 e 2 sin(5t) + 5e 2 cos(5t) on the interval [0, 5] with y(0) = 0;
d2 y
• The ODE 3: dt2 + 2 dy
dt + y = t , on the interval [0, 5] with y(0) = 1 and
dy
dt (0) = 0;

• The ODE 4: 
 dy
 = z, with y(0) = 1,
dt

 dz = −y, z(0) = 0,
dt
This system represents harmonic oscillation, where y is the position and z is the velocity. The second equation
( dz
dt = −y) is analogous to Hooke’s law for a mass-spring system.

1. Calculate the exact (analytical) solution of the given ODEs.

2. Write, for each of the two methods Euler and RK4, a Matlab program that solves the given ODEs with step sizes
h = 0.5, h = 0.1, h = 0.01, h = 0.001 and h = 0.0001.

3. For each ODE, fill the following table2 :

h h = 0.5 h = 0.1 h = 0.01 h = 0.001 h = 0.0001



abs(Err)
Euler N

abs(Err)
RK4 N

The number N typically represents the total number of data points or time steps in your simulation, where
tf −t0
N= h +1

4. Draw in the same figure, the exact solution as well as the estimated solutions.

5. Compare the exact solution with previous approximations. Conclude !.

2 Error calculation is performed by comparing the numerical solutions with the analytically obtained solution.

Dr. Dounia MERADI 10 2023-2024

You might also like