newtonfractal9.m
上传用户:sdhuameng
上传日期:2021-02-23
资源大小:8k
文件大小:2k
源码类别:

分形几何

开发平台:

Matlab

  1. %newton fractal
  2. %Note: this script takes about 7 seconds to complete the fractal
  3. %equation (z+0.5-0.866i)*(z+0.5+0.866i)*((z-1)^(0.4+0.9i))
  4. %
  5. x = linspace(-1.5,1.5,700);
  6. y = linspace(-1.5,1.5,700);
  7. c = zeros(length(y),length(x));
  8.   len_x = length(x);
  9.   len_y = length(y);
  10. for n=1:len_x
  11.     c(n,:) = y(n)+i*x(:);
  12. end
  13. h_msg   = msgbox(' Please Wait ',' ');
  14. zvalues = zeros(len_x,len_y);
  15.     z   = 0+i*0; 
  16.   rough = 0; 
  17.  rough1 = 0; 
  18.  rough2 = 0;  
  19.      m  =  1;
  20.      n  =  len_x*len_y;
  21.    const=0.7+0.9*i;
  22. tic
  23. for m=1:n
  24.      
  25.     k = 0;
  26.     z = c(m);
  27.     rough1 = 0.06;
  28.     rough  = 0;
  29.      while ((k<=30)&&(abs(rough1)> 0.03))
  30.          rough2=  const/(z-1)+1/(z+0.5 - 0.866i)+1/(z+0.5 + 0.866i);   
  31.               z = z - 1/rough2;
  32.          rough1 = z - rough;
  33.          rough  = z;
  34.              k  = k+1;
  35.      end
  36.    zvalues(m) = k;
  37. end
  38. toc
  39. close(h_msg);
  40. %you can also try any one of these colormaps
  41. %cmap = flipud(colormap(hsv));  
  42. %cmap = flipud(colormap(copper));  
  43. %cmap = flipud(colormap(hot));  
  44. %cmap = flipud(colormap(gray));  
  45. %cmap = flipud(colormap(jet));  
  46. %cmap = flipud(colormap(summer)); 
  47. %cmap = flipud(colormap(winter));  
  48. %cmap = flipud(colormap(spring));  
  49. %cmap = flipud(colormap(bone));    
  50. %cmap = colormap(hsv);  
  51. %cmap = colormap(copper);  
  52. %cmap = colormap(hot);  
  53. %cmap = colormap(gray);  
  54. %cmap = colormap(jet);  
  55. %cmap = colormap(summer); 
  56. %cmap = colormap(winter);  
  57. %cmap = colormap(spring);  
  58. %cmap = colormap(bone);    
  59. cmap=flipud(colormap(hot));
  60. colormap(cmap);
  61. image(x,y,zvalues)
  62. axis tight square
  63. %remove comments '%' from 70-75 to save the image
  64. %clear x y c
  65. %zval8 = uint8(zvalues);
  66. %clear zvalues
  67. %rgb   = ind2rgb8( zval8 , cmap );
  68. %imwrite(rgb ,'newton9.png','png') ;