Skip to content

Instantly share code, notes, and snippets.

@benjaminaaron
Last active January 2, 2017 15:39
Show Gist options
  • Save benjaminaaron/db2bef8c99d6f7ee4b40631e37c7600a to your computer and use it in GitHub Desktop.
Save benjaminaaron/db2bef8c99d6f7ee4b40631e37c7600a to your computer and use it in GitHub Desktop.
a minimal implementation of the mandelbrot set in Matlab
grid = 0.01;
iter = 50;
%% mandelbrot set
[Re,Im] = meshgrid(-2:grid:1,-1:grid:1);
z0 = Re + Im*1i; % creates a grid of complex numbers from -2 to 1 on the real axis and from -1 to 1 on the imaginary axis
values = zeros(size(z0));
z = z0;
for n = 1:iter
z = z.^2 + z0;
values(abs(z)<=2) = values(abs(z)<=2) + 1; % increment values that are still bounded by 2
end
surf(Re,Im,values,'EdgeColor','none'); view(2);
%% julia set
figure;
c = -0.4 + 0.6i; % defining value for this julia set, can be any other value too
[Re,Im] = meshgrid(-1.5:grid:1.5,-1.5:grid:1.5);
z = Re + Im*1i;
values = zeros(size(z));
for n = 1:iter
z = z.^2 + c;
values(abs(z)<=2) = values(abs(z)<=2) + 1; % increment values that are still bounded by 2
end
surf(Re,Im,values,'EdgeColor','none'); view(2);
@benjaminaaron
Copy link
Author

benjaminaaron commented Jan 2, 2017

mandelbrot set
mandelbrotset

@benjaminaaron
Copy link
Author

benjaminaaron commented Jan 2, 2017

julia set for -0.4 + 0.6i
juliaset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment