# MATLAB - Image Processing - Douday's rabbit fractal

by GreenPrint
Tags: douday, fractal, image, matlab, processing, rabbit
 Sci Advisor P: 2,751 Mystery solved !!! Ok once I got the python code running it didn't take long to figure out what was happening. In the end it turned out to be fairly simple, the gnu-Octave I'm using thinks infinity > sqrt(5), as do I, but Matlab and Python think otherwise. Well actually it's the way the respective programs handle numerical overflow. There are regions on the map that begin with |z|>2, so not surprisingly when you keep repetitively squaring this you soon get a numerical overflow, (((2^2)^2)^2)^…, it only takes about 10 iterations to exceed even a double precision floating point capability. When this happens Octave returns "+inf" for the absolute value, while matlab and python return "nan" (not a number). So that's it. All the lovely shading that Greenprint (and his matlab textbook) have been getting in their images have been purely the result of bad programming and a glitch in the way the matlab handles numerical overflow.
 PF Gold P: 2,993 Ah, thanks. Numpy has a hack around for the overflow that (efficiently) forces NaN's to zeros: http://www.scipy.org/Numpy_Example_L...21e560ab316ef3 So that  ... z = z**2 + c z = np.nan_to_num(z) a = np.where(np.abs(z)>sqrt5) map[a] = k ... produces the attached image as you would expect Attached Thumbnails
 PF Gold P: 2,993 Python-Numpy comparison with Matlab: http://www.scipy.org/NumPy_for_Matlab_Users

 Related Discussions Science & Math Textbooks 2 Programming & Computer Science 4 Math & Science Software 1 Math & Science Software 1 Engineering, Comp Sci, & Technology Homework 1