Sunday, September 16, 2012

Mandelobrot and Octave

It's a slow Sunday morning, so I popped out the Octave console and did some fractals.


Vx=linspace(-2.1,1,1000);
Vy=linspace(-2,2,1000);
[X,Y]=meshgrid(Vx,Vy);
C=X+i*Y;
M=ones(1000,1000);
Z=zeros(1000,1000);
I=zeros(1000,1000);
n=0;
sameM=0;
while and(n < 10000,sameM < 10)
  n = n+1;
  OLDM=M;
  Z=(M.*Z).^2 + M.*C+(1-M).*Z;
  M=(abs(Z) <= 2);
  I = I +M;
  if (OLDM == M)
    sameM = sameM+1;
  end
end
imagesc(I)