Worksheet 8

淡定淡定。。

=================iter2d.m==================
function r = iter2d(cx,cy,n)
x = 0;
y = 0;
r = [];
for i = 1:n
temp_x = x;
x = x^2-y^2+cx;
y = 2*temp_x*y+cy;
r(i) = x^2+y^2;
end
end

==================chao.m====================
cy = 0;
for cx = -2:2.25/100:0.25
r = iter2d(cx,cy,200);
hold on
plot(r(101:200),cx,’b.’)
end

===============iter_stop.m==================
function m = iter_stop( cx,cy,n )
x = 0;
y = 0;
for k = 1:n
temp_x = x*x-y*y+cx;
y = 2*x*y+cy;
x = temp_x;
r = x*x+y*y;
if(r > 4)
m = k;
return
end
end
m = n;
end

==============Mandelbrot_set.m===============
clear all
cxmin=-2;
cxmax=0.5;
cymin=-1;
cymax=1;
nx=600;
ny=400;
maxit=100;
vals=zeros(ny,nx);
for ix=1:nx
cx=cxmin+(ix-1)/(nx-1)*(cxmax-cxmin);
for iy=1:ny
cy=cymin+(iy-1)/(ny-1)*(cymax-cymin);
m=iter_stop(cx,cy,maxit);
if(m<maxit)
vals(iy,ix)=m;
end
end
end
colormap(‘Jet’)
image(vals)