Advertisement
Guest User

Untitled

a guest
May 26th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.88 KB | None | 0 0
  1. % The fractal visualization of the convergence for Newton's method
  2.  
  3. % range from which we choose complex numbers
  4. min_re=-10;
  5. max_re=10;
  6. min_im=-10;
  7. max_im=10;
  8.  
  9. % degree of the interval comminution
  10.  n_re=300;
  11.  n_im=300;
  12.  
  13. % Accuracy of calculations
  14. tol=0.01;
  15.  
  16. format compact;
  17.  
  18. % matrix, in which every point will be assigned
  19. % a number of Newton's methid iteration
  20. R=zeros (n_re, n_im);
  21.  
  22. % maximum number of steps
  23. max_steps=25;
  24.  
  25.  
  26. % stepsize
  27. delta_re=(max_re-min_re)/n_re;
  28. delta_im=(max_im-min_im)/n_im;
  29.  
  30. % w-polynomial coefficents
  31. % wp-polynomial derivative coefficents
  32.  
  33. % np w=[1,0,0,0,-1] is x^4-1
  34.  
  35. %w=[1,-2 + 3*i,4 +15*i, 164,- 27*i,-155,-135*i];  
  36. %w=[1,0,0,0,-1];
  37. %w=[1,-4,6,-4,1];
  38. %w=[1,0,1];
  39. %w=[7 2 0 49];
  40. w=ones(1,10);
  41. %w=[-5 5 1 2 3 -3 0 4];
  42. %w=randn(1,10);
  43. %w=ones(1,5)+i*[-1, 2, 5, -3, 4];
  44.  
  45. deg=length (w);
  46. wp=zeros (deg-1,1);
  47. for m=1:(deg-1)
  48.     wp (m)=(deg-m)*w (m);
  49. end
  50.  
  51. for j=1:n_re
  52.     for k=1:n_im
  53.         x=min_re+k*delta_re + i*(min_im + j*delta_im);
  54.         if x==0
  55.             x=tol;
  56.         end
  57.         % l-number of iterations from range [0,max_steps]
  58.         l=0;
  59.         flag=0;
  60.         while flag==0
  61.             % Newton's algorithm
  62.             poprawka=horner11 (w,x)/horner11(wp,x);
  63.             x=x-poprawka;
  64.             if norm (poprawka)<=tol
  65.                 flag=1;
  66.             end
  67.             % number of steps
  68.             if l>max_steps
  69.                 flag=1;
  70.             end
  71.             l=l+1;
  72.         end
  73.         % number attribution from range [0,max_steps]
  74.         %assigning colour according to number of steps
  75.         R (j, k)=l;
  76.     end
  77. end
  78.  
  79. % coloristic map
  80. %colormap (hot);
  81. colormap ('default');
  82. brighten (0.5);
  83.  
  84. % function displays matrix R as an image
  85. % value of point (i,j) is the color of this point on the graph
  86. imagesc (R);
  87. colorbar;
  88.  
  89. % turning off the backround, signatures etc.
  90. axis off;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement