Effacer les filtres
Effacer les filtres

How to plot 2d and 3D phase portrait as in the image attachment for chaotic visualization? Also see my code.

1 vue (au cours des 30 derniers jours)
function chaotic
% Define the parameters
k = 1;
lambda_1 = 1;
k_1 = 1;
k_2 = 2;
k_3 = 1;
v_1 = 0.4;
rho = 2;
omega = 1;
mu = 1;
% Calculate W_1 and W_2 based on the given parameters
W_1 = 6 * (k * lambda_1 + rho) / (3 * k * k_3 + 3 * k_2);
W_2 = (k^3 * k_3 + 3*k^2*k_2 + 6*(k*k_1 - v_1)) / (3 * k * k_3 + 3 * k_2);
% Define the time span
tspan = [0 100];
% Generate a grid of initial conditions
[G0, P0] = meshgrid(linspace(0, 0.2, 10), linspace(0, 0.2, 10));
initial_conditions = [G0(:), P0(:)];
% Prepare figures
figure('Name', '2D Phase Portrait');
figure('Name', '3D Phase Portrait');
% Loop over the initial conditions
for i = 1:size(initial_conditions, 1)
% Solve the ODE
[T, Y] = ode45(@(t, y) odesys(t, y, W_1, W_2, omega, mu), tspan, initial_conditions(i, :));
% Plot the 2D phase portrait
figure(findobj('Name', '2D Phase Portrait'));
plot(Y(:, 1), Y(:, 2));
hold on;
% Plot the 3D phase portrait
figure(findobj('Name', '3D Phase Portrait'));
plot3(T, Y(:, 1), Y(:, 2));
hold on;
end
% Finalize the 2D figure
figure(findobj('Name', '2D Phase Portrait'));
xlabel('G');
ylabel('P');
title('2D Phase Portrait');
grid on;
hold off;
% Finalize the 3D figure
figure(findobj('Name', '3D Phase Portrait'));
xlabel('Time');
ylabel('G');
zlabel('P');
title('3D Phase Portrait');
grid on;
hold off;
end
% Nested function for the system of ODEs
function dydt = odesys(t, y, W_1, W_2, omega, mu)
G = y(1);
P = y(2);
dGdt = P;
dPdt = W_1 * G^3 + W_2 * G + omega * cos(mu * t)^2;
dydt = [dGdt; dPdt];
end

Réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by