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

分形几何

开发平台:

Matlab

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