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

分形几何

开发平台:

Matlab

  1. %Newton fractal
  2. %Note: this script takes about 12 seconds to complete 
  3. %the fractal equation z^4-cos(z)
  4. x = linspace(-0.5,0.5,700);
  5. y = linspace(-0.5,0.5,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 - (z*z*z*z-cos(z))/(4*z*z*z+sin(z));
  28.          rough1 = z - rough;
  29.          rough  = z;
  30.              k  = k+1;
  31.      end
  32.    zvalues(m) = k;
  33. end
  34. close(h_msg);
  35. %you can also try any one of these colormaps
  36. %cmap = flipud(colormap(hsv));  
  37. %cmap = flipud(colormap(copper));  
  38. %cmap = flipud(colormap(hot));  
  39. %cmap = flipud(colormap(gray));  
  40. %cmap = flipud(colormap(jet));  
  41. %cmap = flipud(colormap(summer)); 
  42. %cmap = flipud(colormap(winter));  
  43. %cmap = flipud(colormap(spring));  
  44. %cmap = flipud(colormap(bone));    
  45. %cmap = colormap(hsv);  
  46. %cmap = colormap(copper);  
  47. %cmap = colormap(hot);  
  48. %cmap = colormap(gray);  
  49. %cmap = colormap(jet);  
  50. %cmap = colormap(summer); 
  51. %cmap = colormap(winter);  
  52. %cmap = colormap(spring);  
  53. %cmap = colormap(bone);    
  54. cmap=colormap(winter);
  55. colormap(cmap);
  56. imagesc(x,y,zvalues);
  57. axis tight
  58. toc
  59. %remove comments '%' from 68-72 to save the image
  60. %clear x y c
  61. %zval8 = uint8(zvalues);
  62. %clear zvalues
  63. %rgb   = ind2rgb8( zval8 , cmap );
  64. %imwrite(rgb ,'newton2.png','png') ;