File Exchange

image thumbnail

Mandelbrot set vectorized

version 1.0.0.0 (2.78 KB) by Lucio Cetto
Produces the Mandelbrot set using vectorized code.

2 Downloads

Updated 02 Jun 2004

View License

Produces the Mandelbrot set, as other user contributed "m" files, but this submission is VECTORIZED, achieving a speedup of approx 2.5 against a traditional implementation (which is optimized by the JIT). In the past (6.0), a vectorized implementation would achieve speedups up to 100 times faster, this is no longer true.
This is a very instructive example of how to vectorize nested loops.

When being used in interactive mode you can zoom into a region of interest and launch again the computation with a GUI push-button.

Cite As

Lucio Cetto (2020). Mandelbrot set vectorized (https://www.mathworks.com/matlabcentral/fileexchange/1329-mandelbrot-set-vectorized), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

sacrosancttayyar sacrosancttayyar

i like this type of fractals..
with some changes of type it will be more great :)

Sheldon Danielson

Jas Ellis

I haven't tried the program, but I like the vectorisation! :) I added the code to my own a Mandelbrot program, in which I had previously (and, er, idiotically) used NaNs to mask out absolute values greater than 2 (32 seconds, approx). A loop took 24s. Using this linear indexing I got down to 17.5s and Logical indexing shaved another 2s! (Excerpt below).

h = logical(ones(size(X)));
for m=1:50
X(h) = X(h).^2 + X0(h);
h = (abs(X)<2);
A(h) = A(h) + 1;
end;

rash jadhav

Brian Mearns

Good use of vectorization, but I'm not a big fan of the output when nargout == 0. But that's easily enough remidied on my end by assigning an output argumnent. I was also hoping to be able to specify different values for real and imaginary steps.
Also, as I informed the author in an email, in MATLAB R14, the code is slightly broken, but it's easily fixed. In R14, an identifier cannot be used as a function and a variable in the same code, which i is in this file, it's used as the sqrt(-1) (function) and as a counter in a loop (variable). But it's a minor detail and was perfectly legal in earlier versions.

chris seeling

Updates

1.0.0.0

Updating for R14

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories