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.
Lucio Cetto (2020). Mandelbrot set vectorized (https://www.mathworks.com/matlabcentral/fileexchange/1329-mandelbrot-set-vectorized), MATLAB Central File Exchange. Retrieved .
i like this type of fractals..
with some changes of type it will be more great :)
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)));
X(h) = X(h).^2 + X0(h);
h = (abs(X)<2);
A(h) = A(h) + 1;
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.
Updating for R14