Last active
January 2, 2017 15:39
-
-
Save benjaminaaron/db2bef8c99d6f7ee4b40631e37c7600a to your computer and use it in GitHub Desktop.
a minimal implementation of the mandelbrot set in Matlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mandelbrot set