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.
- If c = 0 and lim = 3, then z = [0 0 0] and n = 3.
- If c = 1 and lim = 5, then z = [1 2], and n = length(z) or 2.
- If c = 0.5 and lim = 5, then z = [0.5000 0.7500 1.0625 1.6289] and n = 4.
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]
Solution Stats
Problem Comments
8 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers1777
Suggested Problems
-
30013 Solvers
-
Project Euler: Problem 10, Sum of Primes
2088 Solvers
-
821 Solvers
-
Getting the indices from a vector
11766 Solvers
-
Reverse the elements of an array
1109 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
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
Broken ink to Cleve Moler's PDF
Thanks for noticing that, @Shlomo Geva. The link has been fixed.
Really nice problem, and great very simple solution by the community.