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

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 Comments

I cannot find any Mathworks or File Exchange function named Q_c ?
It would be easier if you posted your code, and also posted the error messages you are encountering.
i need this output. i am not getting correct output by this code and Q_c{z)=z^2+c
%Constants
dr = 800; % Increased resolution of the grid
xmin = -6; xmax = 4.7; % Real range
ymin = -5.5; ymax = 5.5; % Imaginary range
K = 200; % Increased maximum number of iterations
theta = 0.2; % Parameter theta
k = 2; % Parameter k
M = 256; % Number of colors in the colormap
% 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 = 0; % Initial z0
n = 0; % Iteration counter
% Iterate using the Tricorn function
while n <= K
u_n = (1 - theta) * z + theta * (conj(z)^2 + c); % Compute u_n
z_next = conj(u_n)^2 + 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) = floor((M - 1) * n / K); % Store escape time
end
end
% Plotting the fractal
figure; % Create a new figure
imagesc(re, im, E); % Display the escape time matrix
colormap(jet(M)); % 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
Your code does not include any Q_c function, so it is difficult to figure out what you are talking about.
my function Qc(z)=conj(z)^2+c , which is defined by u_n = (1 - theta) * z + theta * (conj(z)^2 + c); this part of my code
Copy your full code here....Show us how did you run along with the input.
? It looks more like
z_next = conj(u_n)^2 + c;
matches to your Qc(z) definition ?
this is the whole algorithm i am trying to generate code for this algorithm but not getting the correct output

Sign in to comment.

 Accepted Answer

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).

More Answers (0)

Categories

Find more on Fractals in Help Center and File Exchange

Products

Release

R2024b

Asked:

on 26 Oct 2024

Answered:

on 30 Oct 2024

Community Treasure Hunt

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

Start Hunting!