% HW5 solution for Julia set plot, using color to show
% how fast orbit goes to infinity
c = -0.470 + 0.587i;                   % choose the c value
c = 1i;                   % choose the c value
x = -1.5:0.005:1.5;
[xx,yy] = meshgrid(x,x);
zz = xx+1i*yy;                  % vectorize using all ICs together in array
co = zeros(size(zz));           % array which counts how many its needed
N=200; tic;
for n=1:N
  nn = find(abs(zz)<2 & ~isnan(zz));  % this avoids calc pts outside 2 or NaN
  co(nn) = n;                   % update the it count array
  zz(nn) = zz(nn).^2 + c;       % fast since vectorized
end
toc
imagesc(x,x,co); axis equal;
% trick to make interior black by redfeining colormap
cmap = jet(256); cmap(end,:)= [0 0 0]; colormap(cmap);
xlabel('Re z'); ylabel('Im z'); title('Julia set in color');
