Sunday, March 6, 2016

Very simple way to plot Mandelbrot set on MATLAB

Here is a simple code to implement Mandelbrot Set in MATLAB

function mandelbrot()
n=200;
nitr=30;

x0=-2; x1=2;
y0=-1.5; y1=1.5;
[x, y]=meshgrid(linspace(x0,x1,n),linspace(y0,y1,n));

c=x+1i*y;
z=zeros(size(c));
k=zeros(size(c));

for ki=1:nitr
    z=z.^2 + c;
    k(abs(z)>3 & k==0)=nitr-ki;
end

figure,
imagesc(k),
colormap jet;
axis square;
end

The idea is very easy, z=z^2 + c, that's all simple and that's all complexity. the resulting Mandelbrot is shown in the following figure.


Thanks to Chris Taylor for providing such simple code and fascinating result. 

No comments:

Post a Comment