Advertisement
Guest User

Sean's Mandelbrot V1 MATLAB

a guest
Nov 30th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. % Mandelbrot Explorer, V1.0
  2. % Sean Irby, November 25th, 2015
  3.  
  4.  
  5. %Function for Choosing a Point
  6. clc;
  7.  
  8.  
  9. %Chart Initiator
  10.  
  11.  
  12. % These numbers set the bounds of the calculation. The mandelbrot set is
  13. % contained within (-2, 1) in x and +/- sqroot 2 in i*y.
  14. xmin = -2;
  15. xmax = 1;
  16. ymin = -1.44;
  17. ymax = 1.44;
  18.  
  19. x = xmin;
  20. y = ymin;
  21.  
  22. %Resolution / Iteration numbers;
  23. d = 0.01 ; %lower for better resolution
  24. N = 25; %Raise for better contrast
  25.  
  26. Nx = abs(xmin/d) + xmax/d + 1;
  27. Ny = abs(ymin/d) + ymax/d + 1;
  28.  
  29. Chart = [Ny;Nx];
  30.  
  31.  
  32. % pDeux calc scan, with a double-for loop that calculates every y for an x,
  33. % resets, y, increments x by one resolution point, then continues
  34. for Cx = 1:Nx
  35. for Cy = 1:Ny
  36.  
  37. %initiates values for the mandelbrot calculation
  38. z = 0;
  39. zo = x+y*1i;
  40. A = 0;
  41. pDeux = 0; % or 1?
  42. j = 1;
  43.  
  44. Stroobap = 0;
  45.  
  46. %pDeux calc Loop; determines if a point is in the set and sets
  47. %pDeux to zero, or determines if it is out of set and records the
  48. %number of iterations to determine pdeux
  49. while (j <= N)
  50. z = (z^2)+zo;
  51. if (abs(z) > 2)
  52. pDeux = j;
  53. j = N + 1;
  54. Stroobap = 1;
  55. end
  56. j = j+1;
  57. end
  58. if Stroobap == 0
  59. pDeux = 0;
  60. end
  61.  
  62. %Saves pDeux (number of iterations until divergance) as the
  63. %variable to plot in the chart, before incrementing y/x.
  64. Chart (Cy,Cx) = pDeux;
  65. Cy = Cy + 1;
  66. y = y + d;
  67.  
  68.  
  69. end
  70. y = ymin;
  71. Cx = Cx + 1;
  72. x = x + d;
  73. end
  74.  
  75.  
  76. Chart = Chart * 3 %improves contrast; for different values of N, the magic interger should change
  77. image(Chart); %Isn't MATLAB easy to plot things with? ;)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement