I am trying to generate code for plotting anti fractals and getting error

조회 수: 73 (최근 30일)
Akansha
Akansha 2024년 10월 26일 7:02
답변: Voss 2024년 10월 30일 19:46

i am taling k=2 in this function Q_c(z) ,thetha=0.2 ,A = [−6, 4.7] × [−5.5, 5.5] tri-corn generated in PMO .i am getting error in my code.

  댓글 수: 10
Akansha
Akansha 2024년 10월 28일 3:57
this output i need but not getting

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

채택된 답변

Voss
Voss 2024년 10월 30일 19:46
Picking z0=c instead of z0=0, correcting the definition of R_base to have 2/theta instead of 2*theta, decreasing the max number of iterations so you can see some color variation, and choosing a similar colormap, gets you closer to the reference image:
%Constants
cmap = [234 55 36; 234 84 40; 238 124 50; 243 178 62; 244 193 67; 246 235 78; 221 250 82; 112 238 113; 40 59 126; 0 0 0]/255;
M = size(cmap,1); % Number of colors in the colormap
dr = 800; % Increased resolution of the grid
xmin = -6; xmax = 4.7; % Real range
ymin = -5.5; ymax = 5.5; % Imaginary range
K = M-1; % maximum number of iterations
theta = 0.2; % Parameter theta
k = 2; % Parameter k
% Create a grid of complex numbers over A
re = linspace(xmin, xmax, dr); % Real part
im = linspace(ymin, ymax, dr); % Imaginary part
c_grid = re + im.' * 1i; % Complex grid A = [-6, 4.7] x [-5.5, 5.5]
% Initialize escape time matrix
E = zeros(size(c_grid)); % Escape time matrix
% Pre-calculate fixed R based on theta and k
R_base = (2 / theta)^(1 / (k - 1));
% Loop over each point in the grid A
for a = 1:dr
for b = 1:dr
c = c_grid(a, b); % Current point in A
R = max(abs(c), R_base); % Calculate R for this c
z = c; % Initial z0
n = 0; % Iteration counter
% Iterate using the Tricorn function
while n <= K
u_n = (1 - theta) * z + theta * (conj(z)^k + c); % Compute u_n
z_next = conj(u_n)^k + c; % Compute z_{n+1}
% Check for escape condition
if abs(z_next) > R
break;
end
z = z_next; % Update z
n = n + 1; % Increment iteration counter
end
% Map n to a color index
E(a, b) = n;
end
end
% Plotting the fractal
figure; % Create a new figure
imagesc(re, im, E); % Display the escape time matrix
colormap(cmap); % Use 'jet' colormap (replace with 'parula', 'hot', etc. if desired)
axis xy; % Correct the axis orientation
set(gca, 'YDir', 'normal'); % Ensure imaginary axis direction is correct
colorbar; % Add a colorbar
title('Anti-Fractal (Tricorn) with PMO Method');
xlabel('Real axis');
ylabel('Imaginary axis');
axis([xmin xmax ymin ymax]); % Set axis limits explicitly
The pseudo-code snippet you posted (Algorithm 2) is for Anti-Julia set, but the reference image you posted is a tricorn, which is based on Algorithm 1, as defined in the attached pdf (downloaded from here).

추가 답변 (0개)

카테고리

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

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by