필터 지우기
필터 지우기

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 (최근 30일)
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
Torsten
Torsten 2023년 6월 23일
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 2023년 6월 24일
I wanted to make a figure like this one!
Just didn't know that how to have 100 different trajectories in one graph.

댓글을 달려면 로그인하십시오.

답변 (1개)

Harshavardhan Putta
Harshavardhan Putta 2023년 6월 26일
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.

카테고리

Help CenterFile Exchange에서 Networks에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by