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”:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1696416/image.png)
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”:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1696421/image.png)
Hope it helps!