MATLAB Report
MATLAB Report
College of Engineering –
Department of Petroleum
Engineering
Differential
Equations in
MATLAB
Made by: Hussien Saaed Salim
Supervised by: Dr. Hyfaa L. Swadi
Introduction:
Differential equations are basic mathematical tools commonly
applied in most scientific and engineering disciplines to describe
changes in dynamic systems. They provide a basic framework
for explaining physical, chemical, and biological phenomena
ranging from space motion to fluid flow and heat transfer.
Advancements in computational science have enabled the
solution to differential equations using software packages, thus
deviating from analytical methods that could be cumbersome or
impossible. Of all software packages available, MATLAB is a
very effective tool for handling Ordinary Differential Equations
(ODE) and Partial Differential Equations (PDE) due to its
inbuilt functions that give effective numerical and symbolic
solutions.
The aim here is to present a complete overview of using
MATLAB to solve differential equations and to outline its vast
collection of tools, ranging from ode45 to dsolve, with
accompanying examples and graphical outputs.
1
1. A Thorough Analysis of Differential Equations
1.1 The Definition of Differential Equations
A differential equation is a mathematical equation that involves
the derivatives of a function and forms a relationship between an
independent variable and their respective derivatives. It is
usually written in the following form:
𝑭(𝒙, 𝒚, 𝒚′ , 𝒚′′ , … . 𝒚𝒏 ) = 𝟎
where:
𝒙: operates as a free variable.
𝒚: denotes an unspecified function.
𝒚′ , 𝒚′′ , … . 𝒚𝒏 : are the derivatives of 𝑦
3
3. Practical Examples in MATLAB
3.1 Solving an Ordinary Differential Equation Using ode45
We aim to solve the following differential equation:
𝑑𝑦
= −2𝑦, 𝑦(0) = 1
𝑑𝑥
MATLAB code:
function dydx = myODE(x, y)
dydx = -2 * y;
end
x_span = [0 5]; % Solution range from 0 to 5
y0 = 1; % Initial condition
[x, y] = ode45(@myODE, x_span, y0);
plot(x, y, 'r', 'LineWidth', 2)
xlabel('x')
ylabel('y')
title('Solution of Differential Equation using
ode45')
grid on
Results Analysis:
4
3.2 Solving a System of Differential Equations
Using ode45 consider solving the following system:
𝑑𝑥 𝑑𝑦
= 𝑦, = −𝑥
𝑑𝑡 𝑑𝑡
MATLAB code:
function dydt = mySystem(t, Y)
dydt = [Y(2); -Y(1)];
end
t_span = [0 10];
Y0 = [1; 0];
[t, Y] = ode45(@mySystem, t_span, Y0);
plot(t, Y(:,1), 'b', t, Y(:,2), 'r')
legend('x(t)', 'y(t)')
xlabel('t')
ylabel('Values')
title('Solution of a System of Differential
Equations')
grid on
Results Analysis
The solution appears as a simple harmonic motion, which is
expected since this system represents sinusoidal oscillations
similar to the motion of a simple pendulum.
5
Conclusion
MATLAB is commonly known to be an extremely effective and
very powerful software for computing used extensively and
extensively in a variety of fields for the solution to differential
equations using both symbolic and numerical approaches. This
is a very impressive ability that allows engineers and scientists
to solve dynamic systems with unprecedented speed and
efficacy in the field, making MATLAB a highly useful and
indispensable tool in scientific research and in a wide variety of
different fields in engineering.
References
1. Chapra, S. C., & Canale, R. P. (2015). Numerical Methods
for Engineers. McGraw-Hill Education.
2. MATLAB Documentation -
https://www.mathworks.com/help/matlab/
3. Kreyszig, E. (2011). Advanced Engineering Mathematics.
Wiley.