The Mandelbrot Set is built around a simple iterative equation.
z(1) = c z(n+1) = z(n)^2 + c
For any complex c, we can continue this iteration until either abs(z(n+1)) > 2 or n == lim, then return the iteration count n.
For a matrix of complex numbers C, return a corresponding matrix N such that each element of N is the iteration count n for each complex number c in the matrix C, subject to the iteration count limit of lim.
If C = [0 0.5; 1 4] and lim = 5, then N = [5 4; 2 1]
Cleve Moler has a whole chapter on the Mandelbrot set in his book Experiments with MATLAB: Chapter 10, Mandelbrot Set (PDF)
For c==4 and other numbers where abs(c)>2, I think the function should be defined to return 0 rather than 1.
comment
I am really stuck on this one. I know it is likley me not the question but I cannot figure out why in the final validation, -2i should give N=1, I get it to be N=2? any help is appriciated, this is the only situlation where code fails.
For people like me that hoped this challenge would end with a pretty picture:
`[X,Y]=meshgrid(-2:0.0025:2,-2:0.0025:2);C=X+i.*Y;N=mandelbrot(C,50);imagesc(N)`
@Ratchet_Hamster
for complex no, u need to take the absolute value to check if it is greater than 2
It dseon't mettar waht oedrr the lrettes in a wrod are.
545 Solvers
Project Euler: Problem 1, Multiples of 3 and 5
1642 Solvers
199 Solvers
Create a two dimensional zero matrix
287 Solvers
489 Solvers