Plot of the Rossler Attractor

46 次查看(过去 30 天)
Conor Pierce
Conor Pierce 2024-5-14
编辑: Zinea 2024-5-16
I have made an m-file to plot the Rossler Attractor using the equations and a fourth order Runge Kutta methid but the plot lines are very pointed and do not appear smooth, has anyone any suggestions about how i can create a better Attractor? step size, h, used was 0.175. The plot of the Attractor can be found below, thank you.

回答(1 个)

Zinea
Zinea 2024-5-16
编辑:Zinea 2024-5-16
I have reproduced a similar plot of the Rossler attractor with the following scriptrough_rossler_script.m:
function rossler_attractor_RK4
% Parameters for the Rössler attractor
a = 0.2;
b = 0.2;
c = 5.7;
% Initial conditions
y0 = [0; 2; 0];
% Time span
tStart = 0;
tEnd = 200;
h = 0.175; % Fixed step size
% Time vector
tVec = tStart:h:tEnd;
nSteps = length(tVec);
% Preallocate the solution array
Y = zeros(nSteps, 3);
Y(1,:) = y0';
% RK4 integration
for i = 1:nSteps-1
t = tVec(i);
y = Y(i,:)';
k1 = h * rossler(t, y, a, b, c);
k2 = h * rossler(t + 0.5*h, y + 0.5*k1, a, b, c);
k3 = h * rossler(t + 0.5*h, y + 0.5*k2, a, b, c);
k4 = h * rossler(t + h, y + k3, a, b, c);
Y(i+1,:) = y + (k1 + 2*k2 + 2*k3 + k4)/6;
end
% Plot
plot3(Y(:,1), Y(:,2), Y(:,3), 'LineWidth', 1.5);
xlabel('x');
ylabel('y');
zlabel('z');
title('Rössler Attractor with RK4');
grid on;
end
function dydt = rossler(t, y, a, b, c)
% Rössler attractor differential equations
dydt = zeros(3,1);
dydt(1) = -y(2) - y(3);
dydt(2) = y(1) + a*y(2);
dydt(3) = b + y(3)*(y(1) - c);
end
Output plot from the “rough_rossler_script.m”:
To make the plot smoother, the step size (h) must be decreased because it will lead to the calculation of more points along the trajectory. The step size (h) is reduced to 0.01 from the earlier code where it was 0.175.
The modified scriptsmooth_rossler_script.mis given below:
function rossler_attractor_RK4_smooth
% Parameters for the Rössler attractor
a = 0.2;
b = 0.2;
c = 5.7;
% Initial conditions
y0 = [0; 2; 0];
% Time span
tStart = 0;
tEnd = 200;
h = 0.01; % Decreased step size for smoother plot
% Time vector
tVec = tStart:h:tEnd;
nSteps = length(tVec);
% Preallocate the solution array
Y = zeros(nSteps, 3);
Y(1,:) = y0';
% RK4 integration loop
for i = 1:nSteps-1
t = tVec(i);
y = Y(i,:)';
k1 = h * rossler(t, y, a, b, c);
k2 = h * rossler(t + 0.5*h, y + 0.5*k1, a, b, c);
k3 = h * rossler(t + 0.5*h, y + 0.5*k2, a, b, c);
k4 = h * rossler(t + h, y + k3, a, b, c);
Y(i+1,:) = y + (k1 + 2*k2 + 2*k3 + k4)/6;
end
% Plot
plot3(Y(:,1), Y(:,2), Y(:,3), 'LineWidth', 1.5);
xlabel('x');
ylabel('y');
zlabel('z');
title('Smooth Rössler Attractor with RK4');
grid on;
end
function dydt = rossler(t, y, a, b, c)
% Rössler attractor differential equations
dydt = zeros(3,1);
dydt(1) = -y(2) - y(3);
dydt(2) = y(1) + a*y(2);
dydt(3) = b + y(3)*(y(1) - c);
end
Output plot from “smooth_rossler_script.m”:
Hope it helps!

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by