Need help plotting these 'Time-Series Graphs' in the 'Chaotic attractor' for loop
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Would like to make the code more efficent, and optimized, please help
clear variables;
set(0, 'DefaultAxesFontName', 'CourierNew', 'DefaultAxesFontSize', 11);
%% 1) Non-Analytic Basin
% Global initial conditions:-
NT = 2^12; % No. of iterations
n = 0:1:NT; % Discrete time domain
epsilon = 1e-6; % very small number
Rmax = 2; % Radius of the circle around the basin, outside of which the value goes to infinity
N = 256; % Resolution of IC plane NxN grid)
x0_vec = linspace(-1.8,1.2,N); % Range of x0 ICs
y0_vec = linspace(-1.8,1.2,N); % Range of y0 ICs
p = zeros(N,N); % initalizing P
% Use nested k, kk loops to cycle through the plane of inital conditions
% (keep y0 fixed then vary x0)
for k = 1:length(y0_vec) % iterate the loop till the no. of values in the y0_vec array
y0 = y0_vec(k); % set y0 = the kth value of the y0_vec array
for kk = 1:length(x0_vec) % iterate the loop till the no. of values in the x0_vec array
x0 = x0_vec(kk); % set x0 = the kkth value of the x0_vec array
x(1) = x0; % set the first value in the x-array = to x0
y(1) = y0; % set the first value in the y-array = to 1i*y0 (complex)
for j = 1:NT
x(j+1) = ((x(j)).^2)-((y(j)).^2)+x(j) - 0.297*y(j) + 0.048; % Nonanalytic map
y(j+1) = 2*x(j)*y(j)+x(j)+0.6*y(j); % Nonanaytic map
z(j+1) = complex(x(j+1), y(j+1)); % Set z = x + iy
% Interrogating the dataset
if abs(z(j+1)) >= Rmax % if z is greater than 2
P(k, kk) = 2; % P goes to infinity
break
else % Otherwise, nothing
end
end
if j == NT % If j reaches NT and z is not greater than Rmax, P = 1
P(k,kk) = 1;
else % Otherwise nothing
end
end
end
% Plot the basins using pcolor:-
figure (1);
hold on;
pcolor(x0_vec, y0_vec, -P)
axis square; colormap hot; shading flat; colorbar;
xlabel('x_0'); ylabel('y_0');
title('Non-Analytic Fractal Basin');
%% 2) Plot the Chaotic attractors
% Local variables
x0c_vec = [0, 0]; % array of initial x-vals
y0c_vec = [0.6, 0.6+epsilon]; % array of initial y-vals
Ntrans = 1024; % No. of transitent iterations to be cut out
nt = 0:1:Ntrans; % transient time domain
line_color = ["#a0dcfd", "#1f53d5"]; % specifying color array
for m=1:2
x0c = x0c_vec(m);
y0c = y0c_vec(m);
xct(m, 1) = x0c; % set the first value in the x-transient array= to x0c
yct(m, 1) = y0c; % set the first value in the y-transient array = to y0c
for mm = 1:Ntrans
xct(m, mm+1) = ((xct(m, mm)).^2)-((yct(m, mm)).^2)+xct(m, mm) - 0.297*yct(m, mm) + 0.048; % Nonanalytic map
yct(m, mm+1) = 2*xct(m, mm)*yct(m, mm)+xct(m, mm)+0.6*yct(m, mm);
end
xc(m, 1) = xct(m, Ntrans); % set the first value in the xc array= to the final iterated value of x0c
yc(m, 1) = yct(m, Ntrans); % set the first value in the yc array= to the final iterated value of y0c
for j = 1:NT
xc(m, j+1) = ((xc(m, j)).^2)-((yc(m, j)).^2)+xc(m, j) - 0.297*yc(m, j) + 0.048; % Nonanalytic map
yc(m, j+1) = 2*xc(m, j)*yc(m, j)+xc(m, j)+0.6*yc(m, j);
end
plot(xc, yc, '.', 'MarkerSize', 2); % Plotting the Chaotic attractor
colororder(line_color);
end
%% 3) Plot the time-series figures
% Generate a figure
figure (2);
sgtitle('Non-Analytic Time-series');
% 3.1) Plot the subfigure
subplot(2,1,1);
plot(nt,xct,'-');
axis ([0, 120, -1, 1]);
grid on; box on;
xticks(0:10:120); yticks(-1:0.25:1);
xticklabels({'0','','20','','40','','60','','80','','100','','120'});
yticklabels({'-1','','-0.5','','0','','0.5','','1.0'});
xlabel('No. of iterations/n'); ylabel('x_n');
title('Real values');
legend('IC 1: x0', 'IC 2: x0+\epsilon');
% 3.2) Plot the subfigure
subplot(2,1,2);
plot(nt,yct,'-');
axis ([0, 120, -1, 1]);
grid on; box on; hold on;
xticks(0:10:120); yticks(-1:0.25:1);
xticklabels({'0','','20','','40','','60','','80','','100','','120'});
yticklabels({'0','','0.2','','0.4','','0.6','','0.8','','1.0','','1.2','','1.4','','1.6','','1.8','','2.0'});
xlabel('No. of iterations/n'); ylabel('y_n');
title('Imaginary values');
legend('IC 1: y0', 'IC 2: y0+\epsilon');
1 Commento
Mr. Pavl M.
il 13 Ott 2024
x, y and their derivatives to make as a 2D matrix, then 2 for loops will be shrunk into 1.
How?
What do you mean by optimization, in which terms, what to minimize, what to maximize?
I found your code and idea very interesting and very valuable.
I am a solopreneour yet. No freelance platforms, nor options are available for me. Let's get to know better, other people got not acquinted and made very assymetric problematic chaos to me by closing for me opportunities to earn money by specific academic write-ups and engineering codeworks.
What are the natural applications of it?
How can we make money on it?
There is periodicity (cyclic pattern) found in time series. Symmetric time found, what are the stablest points of it?
First corrections found to the code:
clc
clear variables;
set(0, 'DefaultAxesFontName', 'CourierNew', 'DefaultAxesFontSize', 11);
%% 1) Non-Analytic Basin
% Global initial conditions:-
NT = 2^12; % No. of iterations
n = 0:1:NT; % Discrete time domain
epsilon = 1e-6; % very small number
Rmax = 2; % Radius of the circle around the basin, outside of which the value goes to infinity
N = 256; % Resolution of IC plane NxN grid)
x0_vec = linspace(-1.8,1.2,N); % Range of x0 ICs
y0_vec = linspace(-1.8,1.2,N); % Range of y0 ICs
p = zeros(N,N); % initalizing P
% Use nested k, kk loops to cycle through the plane of inital conditions
% (keep y0 fixed then vary x0)
for k = 1:length(y0_vec) % iterate the loop till the no. of values in the y0_vec array
y0 = y0_vec(k); % set y0 = the kth value of the y0_vec array
for kk = 1:length(x0_vec) % iterate the loop till the no. of values in the x0_vec array
x0 = x0_vec(kk); % set x0 = the kkth value of the x0_vec array
x(1) = x0; % set the first value in the x-array = to x0
y(1) = y0; % set the first value in the y-array = to 1i*y0 (complex)
for j = 1:NT
x(j+1) = ((x(j)).^2)-((y(j)).^2)+x(j) - 0.297*y(j) + 0.048; % Nonanalytic map
y(j+1) = 2*x(j)*y(j)+x(j)+0.6*y(j); % Nonanalytic map
z(j+1) = complex(x(j+1), y(j+1)); % Set z = x + iy
% Interrogating the dataset
if abs(z(j+1)) >= Rmax % if z is greater than 2
P(k, kk) = 2; % P goes to infinity
break
else % Otherwise, nothing
end
end
if j == NT % If j reaches NT and z is not greater than Rmax, P = 1
P(k,kk) = 1;
else % Otherwise nothing
end
end
end
% Plot the basins using pcolor:-
figure (1);
hold on;
pcolor(x0_vec, y0_vec, -P)
axis square; colormap hot; shading flat; colorbar;
xlabel('x_0'); ylabel('y_0');
title('Non-Analytic Fractal Basin');
%% 2) Plot the Chaotic attractors
% Local variables
x0c_vec = [0, 0]; % array of initial x-vals
y0c_vec = [0.6, 0.6+epsilon]; % array of initial y-vals
Ntrans = 1024; % No. of transitent iterations to be cut out
nt = 0:1:Ntrans; % transient time domain
line_color = ["#a0dcfd", "#1f53d5"]; % specifying color array
for m=1:2
x0c = x0c_vec(m); y0c = y0c_vec(m);
xct(m, 1) = x0c; % set the first value in the x-transient array= to x0c
yct(m, 1) = y0c; % set the first value in the y-transient array = to y0c
for mm = 1:Ntrans
xct(m, mm+1) = ((xct(m, mm)).^2)-((yct(m, mm)).^2)+xct(m, mm) - 0.297*yct(m, mm) + 0.048; % Nonanalytic map
yct(m, mm+1) = 2*xct(m, mm)*yct(m, mm)+xct(m, mm)+0.6*yct(m, mm);
end
xc(m, 1) = xct(m, Ntrans); % set the first value in the xc array= to the final iterated value of x0c
yc(m, 1) = yct(m, Ntrans); % set the first value in the yc array= to the final iterated value of y0c
for j = 1:NT
xc(m, j+1) = ((xc(m, j)).^2)-((yc(m, j)).^2)+xc(m, j) - 0.297*yc(m, j) + 0.048; % Nonanalytic map
yc(m, j+1) = 2*xc(m, j)*yc(m, j)+xc(m, j)+0.6*yc(m, j);
end
plot(xc, yc, '.', 'MarkerSize', 2); % Plotting the Chaotic attractor
colororder(line_color);
end
%% 3) Plot the time-series figures
% Generate a figure
figure (2);
sgtitle('Non-Analytic Time-series');
% 3.1) Plot the subfigure
subplot(2,1,1);
plot(nt,xct,'-');
axis ([0, 120, -1, 1]);
grid on; box on;
xticks(0:10:120); yticks(-1:0.25:1);
xticklabels({'0','','20','','40','','60','','80','','100','','120'});
yticklabels({'-1','','-0.5','','0','','0.5','','1.0'});
xlabel('No. of iterations'); ylabel('x_n');
title('Real values');
legend('IC 1: x0', 'IC 2: x0+\epsilon');
% 3.2) Plot the subfigure
subplot(2,1,2);
plot(nt,yct,'-');
axis ([0, 120, -1, 1]);
grid on; box on; hold on;
xticks(0:10:120); yticks(-1:0.25:1);
xticklabels({'0','','20','','40','','60','','80','','100','','120'});
yticklabels({'0','','0.2','','0.4','','0.6','','0.8','','1.0','','1.2','','1.4','','1.6','','1.8','','2.0'});
xlabel('No. of iterations'); ylabel('y_n');
title('Imaginary values');
legend('IC 1: y0', 'IC 2: y0+\epsilon');
Risposte (1)
Walter Roberson
il 13 Ott 2024
Your first
for j = 1:NT
and your
for mm = 1:Ntrans
and your second
for j = 1:NT
are all building arrays iteratively, with each iteration depending on the iteration before. You will not be able to improve the performance of those steps.
However, you might possibly be able to vectorize the first for j = 1:NT loop over all of the x0_vec values.
0 Commenti
Vedere anche
Categorie
Scopri di più su Discrete Data Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!