TP 1 NSL
TP 1 NSL
Electrical Engineering
University August 20th,1955 of Skikda
Groupe 1:
• Dekali Nawfel
II-Application 1:
1-
syms y(t)
Dy = diff(y, t);
D2y = diff(y, t, 2);
eqn = D2y + 0.5 * Dy^2 == 1;
conds = [y(0) == 0, Dy(0) == 0];
ySol = dsolve(eqn, conds);
pretty(ySol)
2-
yt = vectorize(ySol);
t = -20:0.25:20;
yt_vals = eval(yt);
figure(1)
plot(t, yt_vals, 'b', 'LineWidth', 2)
xlabel('Temps t'), ylabel('y(t)')
title('Solution analytique de y(t)')
grid on
Solution analytique de y(t)
30
25
20
y(t)
15
10
0
-20 -15 -10 -5 0 5 10 15 20
Temps t
3-
We put :
4-
Tspan = -20:0.25:20;
x0 = [0 0]; % [y(0), dy(0)]
[t_num, x] = ode45(@nonlinear_system, Tspan, x0);
figure(1)
hold on
plot(t_num, x(:,1), 'r--', 'LineWidth', 2)
legend('Solution analytique', 'Solution numérique')
60
Solution analytique
50
40
30
20
10
0
-20 -15 -10 -5 0 5 10 15 20
5-
figure(2)
plot(x(:,1), x(:,2), 'm', 'LineWidth', 2)
xlabel('x_1 (y)'), ylabel('x_2 (dy/dt)')
title('Plan de phase : x_1 vs x_2')
grid on
Plan de phase : x 1 vs x 2
1.5
1
x (dy/dt)
2
0.5
0
0 10 20 30 40 50 60
x 1 (y)
6- Comments :
The analytical solution (if explicitly found using dsolve) and the numerical solution match
closely, demonstrating the accuracy of ode45.
The phase plot shows the relationship between position and velocity in the dynamic system —
it allows us to observe whether the motion is bounded, divergent, or exhibits oscillatory behavior.
III-Application 2:
1-with this state variable
x1=y
x2=dy÷dt
-we found :
2:
clc; clear; close all
eps_values = [0.1, 1, 10];
initial_conditions = [2 0; 0.2 0; 4 0];
Tspan = [0 20];
figure_index = 1;
for e = eps_values
for k = 1:size(initial_conditions, 1)
x0 = initial_conditions(k, :);
e = 0;
for k = 1:size(initial_conditions, 1)
x0 = initial_conditions(k, :);
ode_fun = @(t, x) van_der_pol(t, x, e);
[t, x] = ode45(ode_fun, Tspan, x0);
figure(figure_index)
plot(x(:,1), x(:,2), 'LineWidth', 2)
xlabel('x_1 = y(t)')
ylabel('x_2 = dy/dt')
title(['Phase plot for \epsilon = 0 and IC = [', num2str(x0(1)), ', ', num2str(x0(2)), ']'])
grid on
figure_index = figure_index + 1;
end
0.5 0.05
-6
x 2 = dy/dt
x 2 = dy/dt
0
0
x 2 = dy/dt
-8
-0.5
-0.05 -10
-1
-12
-1.5 -0.1
-2 -14
-0.15
-2.5 -16
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x 1 = y(t) -0.2
-0.2 -0.15 -0.1 -0.05 0 0.05 0.1 0.15 0.2 -18
x 1 = y(t) -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0.5
x 1 = y(t) 7
x 10
0
Phase plot for = 1 and IC = [2, 0]
3 x 10
21
Phase plot for = 1 and IC = [4, 0]
0
-0.02
2
-1
1 -0.04
x 2 = dy/dt -2
x 2 = dy/dt
0
-0.06
-3
x 2 = dy/dt
-1
-0.08
-2
-4
-3
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
-0.1
x 1 = y(t)
-5
-0.12 -6
-0.05 0 0.05 0.1 0.15 0.2
x 1 = y(t)
-7
-3 -2.5 -2 -1.5 -1 -0.5 0 0.5
x 1 = y(t) 7
x 10
-0.004 0
-1
-0.006 -2
-2 -4
-0.008
x 2 = dy/dt
x 2 = dy/dt
-6
-0.01
-3
x 2 = dy/dt
-8
-0.012
-4 -10
-0.014
-12
-0.016 -5
-14
-0.018 -1 -0.5 0 0.5 1 1.5 2
x 1 = y(t)
-6
-0.02
0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22
x 1 = y(t) -7
-3 -2.5 -2 -1.5 -1 -0.5 0 0.5
x 1 = y(t) 7
x 10
3:
Phase plot for = 0 and IC = [0.2, 0] Phase plot for = 0 and IC = [4, 0]
0.2 4
Phase plot for = 0 and IC = [2, 0]
2
0.15 3
1.5
0.1 2
1
0.05 1
0.5
x 2 = dy/dt
x 2 = dy/dt
x 2 = dy/dt
0 0 0
-0.5 -0.05 -1
-1
-0.1 -2
-1.5
-0.15 -3
-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
-0.2 -4
x 1 = y(t) -0.2 -0.15 -0.1 -0.05 0 0.05 0.1 0.15 0.2 -4 -3 -2 -1 0 1 2 3 4
x 1 = y(t) x 1 = y(t)
4-Comments :
Interpretation (for the final comment)
IV-Conclusion :
The study of nonlinear Ordinary Differential Equations using MATLAB highlights both the
complexity and richness of nonlinear dynamic systems. Through analytical and numerical
methods, we observed how the behavior of solutions can drastically change depending on the
system parameters, particularly the nonlinearity coefficient ε. MATLAB’s numerical solvers, such
as ode45, have proven to be highly effective for approximating solutions where analytical
expressions are difficult or impossible to obtain. By analyzing phase portraits and solution curves,
we gained valuable insights into the system's dynamics, including periodic motion, divergence,
and the emergence of limit cycles. This project underscores the importance of numerical tools in
modern applied mathematics and engineering, especially when dealing with systems that cannot be
solved analytically.