|
When drawing the Julia set, we can use the real number iteration as following:
clc, clear
a=-0.11; b=0.65; r=2; N=60; hold on
for x0=-r:0.02:r
for y0=-r:0.02:r
x(1)=x0; y(1)=y0;
if x0^2+y0^2<=r^2
for n=1:N
x(n+1)=x(n)^2-y(n)^2+a;
y(n+1)=2*x(n)*y(n)+b;
end
if x(end)^2+y(end)^2<r^2
plot(x0,y0,'.')
end
end
end
end
We can use the complex number iteration as follows:
clc, clear
c=-0.11+0.65*i; r=2; N=60; hold on
for x0=-r:0.02:r
for y0=-r:0.02:r
z0=x0+y0*i; z=z0;
if abs(z0)<r
for n=1:N
z=z^2+c;
end
if abs(z)<r
plot(z0,'.')
end
end
end
end
But the graph of the above program is wrong. We must correct the program to get the right results as follows:
clc, clear
c=-0.11+0.65*i; r=2; N=60; hold on
for x0=-r:0.02:r
for y0=-r:0.02:r
z0=x0+y0*i; z=z0;
if abs(z0)<r
for n=1:N
z=z^2+c;
end
if abs(z)<r
if isreal(z0)
plot(z0,0,'.') %if z0 is real number, plot has wrong.
else
plot(z0,'.') %if z0 is complex number, plot is right.
end
end
end
end
end
|