newtonfractal5.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)^const)
  4. %0.7+0.9*i;0.5+0.3*i;0.4+0.9i
  5. const_list = {'0.5';'0.7+0.9*i';'0.5+0.3*i';'0.4+0.9i'};
  6.     [s,v]  = listdlg('PromptString','Select a file:',...
  7.                 'SelectionMode','single',...
  8.                 'ListString',const_list);
  9. if v==1   %if OK button is clicked
  10. const=str2num(const_list{s});
  11. x = linspace(-1.5,1.5,700);
  12. y = linspace(-1.5,1.5,700);
  13. c = zeros(length(y),length(x));
  14.   len_x = length(x);
  15.   len_y = length(y);
  16. for n=1:len_x
  17.     c(n,:) = y(n)+i*x(:);
  18. end
  19. h_msg   = msgbox(' Please Wait ',' ');
  20. zvalues = zeros(len_x,len_y);
  21.     z   = 0+i*0; 
  22.   rough = 0; 
  23.  rough1 = 0; 
  24.  rough2 = 0;  
  25.      m  =  1;
  26.      n  =  len_x*len_y;
  27. tic
  28. for m=1:n
  29.      
  30.     k = 0;
  31.     z = c(m);
  32.     rough1 = 0.06;
  33.     rough  = 0;
  34.      while ((k<=30)&&(abs(rough1)> 0.01))
  35.          rough2=  const/(z-1)+1/(z+0.5 - 0.866i)+1/(z+0.5 + 0.866i);   
  36.               z = z - 1/rough2;
  37.          rough1 = z - rough;
  38.          rough  = z;
  39.              k  = k+1;
  40.      end
  41.    zvalues(m) = k;
  42. end
  43. toc
  44. close(h_msg);
  45. %you can also try any one of these colormaps
  46. %cmap = flipud(colormap(hsv));  
  47. %cmap = flipud(colormap(copper));  
  48. %cmap = flipud(colormap(hot));  
  49. %cmap = flipud(colormap(gray));  
  50. %cmap = flipud(colormap(jet));  
  51. %cmap = flipud(colormap(summer)); 
  52. %cmap = flipud(colormap(winter));  
  53. %cmap = flipud(colormap(spring));  
  54. %cmap = flipud(colormap(bone));    
  55. %cmap = colormap(hsv);  
  56. %cmap = colormap(copper);  
  57. %cmap = colormap(hot);  
  58. %cmap = colormap(gray);  
  59. %cmap = colormap(jet);  
  60. %cmap = colormap(summer); 
  61. %cmap = colormap(winter);  
  62. %cmap = colormap(spring);  
  63. %cmap = colormap(bone);    
  64. cmap=flipud(colormap(jet));
  65. colormap(cmap);
  66. image(x,y,zvalues)
  67. axis tight square
  68. %remove comments '%' from 81-85 to save the image
  69. %clear x y c
  70. %zval8 = uint8(zvalues);
  71. %clear zvalues
  72. %rgb   = ind2rgb8( zval8 , cmap );
  73. %imwrite(rgb ,'newton5.png','png') ;
  74. end