Filter löschen
Filter löschen

Kindly check if my code for the evolution of dynamical system is correct. I believe that the code is correct till I give the command to plot. Errors are in the plotting part.

3 Ansichten (letzte 30 Tage)
By this code I want to plot the Evolution of the Lorenz dynamical equations for 100 randomly chosen initial conditions. with the initials conditions visualized as red circles. I wanted to show that all trajectories(visualized with randomly chosen different colours) collapse to an attractor.
%%
dt=0.01; T=8; t=0:dt:T;
b=8/3; sig=10; r=28;
Lorenz = @(t,x)([ sig * (x(2) - x(1)) ; ...
r * x(1)-x(1) * x(3) - x(2) ; ...
x(1) * x(2) - b*x(3) ]);
ode_options = odeset('RelTol',1e-10, 'AbsTol',1e-11);
input=[]; output=[];
for j=1:100 % training trajectories
x0=30*(rand(3,1)-0.5);
[t,y] = ode45(Lorenz,t,x0);
input=[input; y(1:end-1,:)];
output=[output; y(2:end,:)];
end
plot3(y(:,1), y(:,2), y(:,3)), grid
xlabel('x(t)'), ylabel('y(t)'), zlabel('z(t)')
title('Evolution of the Lorenz dynamical equations for 100 randomly chosen initial conditions (red circles).')
axis tight
  2 Kommentare
Torsten
Torsten am 23 Jun. 2023
100 curves in one graph ? Then plot within the loop using the command "hold on" before entering the loop.
Why do you fill the arrays "input" and "output" if you don't use them ?
Sibghat Qureshi
Sibghat Qureshi am 24 Jun. 2023
I wanted to make a figure like this one!
Just didn't know that how to have 100 different trajectories in one graph.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Harshavardhan Putta
Harshavardhan Putta am 26 Jun. 2023
Hi,
I understand that you have concerns regarding the plotting part of your code for the evolution of a dynamical system. You believe that the code is correct until the plotting section, where you are encountering errors. Your goal is to plot the evolution of the Lorenz dynamical equations for 100 randomly chosen initial conditions, with the initial conditions visualized as red circles. Additionally, you aim to demonstrate that all trajectories, visualized with randomly chosen different colors, collapse to an attractor.
After reviewing your code, it seems that there are a few modifications needed in the plotting part. I have made the necessary adjustments to address the errors and achieve the desired visualization. Please find the updated code below:
dt = 0.01;
T = 8;
t = 0:dt:T;
b = 8/3;
sig = 10;
r = 28;
Lorenz = @(t, x)([sig * (x(2) - x(1)) ; r * x(1) - x(1) * x(3) - x(2) ; x(1) * x(2) - b * x(3)]);
ode_options = odeset('RelTol', 1e-10, 'AbsTol', 1e-11);
figure;
hold on;
for j = 1:100 % Generate trajectories for 100 randomly chosen initial conditions
x0 = 30 * (rand(3, 1) - 0.5);
[t, y] = ode45(Lorenz, t, x0, ode_options);
% Plot trajectory with randomly chosen color
color = rand(1, 3);
plot3(y(:, 1), y(:, 2), y(:, 3), 'Color', color);
end
hold off;
grid on;
xlabel('x(t)');
ylabel('y(t)');
zlabel('z(t)');
title('Evolution of the Lorenz dynamical equations for 100 randomly chosen initial conditions (red circles)');
axis tight;
Please refer to the following documentation for more information.
I hope it helps!
Thanks.

Kategorien

Mehr zu Networks finden Sie in Help Center und File Exchange

Produkte


Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by