Plot of the Rossler Attractor
46 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Zinea
on 16 May 2024
Edited: Zinea
on 16 May 2024
I have reproduced a similar plot of the Rossler attractor with the following script “rough_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 script “smooth_rossler_script.m” is 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!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!