Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % The fractal visualization of the convergence for Newton's method
- % range from which we choose complex numbers
- min_re=-10;
- max_re=10;
- min_im=-10;
- max_im=10;
- % degree of the interval comminution
- n_re=300;
- n_im=300;
- % Accuracy of calculations
- tol=0.01;
- format compact;
- % matrix, in which every point will be assigned
- % a number of Newton's methid iteration
- R=zeros (n_re, n_im);
- % maximum number of steps
- max_steps=25;
- % stepsize
- delta_re=(max_re-min_re)/n_re;
- delta_im=(max_im-min_im)/n_im;
- % w-polynomial coefficents
- % wp-polynomial derivative coefficents
- % np w=[1,0,0,0,-1] is x^4-1
- %w=[1,-2 + 3*i,4 +15*i, 164,- 27*i,-155,-135*i];
- %w=[1,0,0,0,-1];
- %w=[1,-4,6,-4,1];
- %w=[1,0,1];
- %w=[7 2 0 49];
- w=ones(1,10);
- %w=[-5 5 1 2 3 -3 0 4];
- %w=randn(1,10);
- %w=ones(1,5)+i*[-1, 2, 5, -3, 4];
- deg=length (w);
- wp=zeros (deg-1,1);
- for m=1:(deg-1)
- wp (m)=(deg-m)*w (m);
- end
- for j=1:n_re
- for k=1:n_im
- x=min_re+k*delta_re + i*(min_im + j*delta_im);
- if x==0
- x=tol;
- end
- % l-number of iterations from range [0,max_steps]
- l=0;
- flag=0;
- while flag==0
- % Newton's algorithm
- poprawka=horner11 (w,x)/horner11(wp,x);
- x=x-poprawka;
- if norm (poprawka)<=tol
- flag=1;
- end
- % number of steps
- if l>max_steps
- flag=1;
- end
- l=l+1;
- end
- % number attribution from range [0,max_steps]
- %assigning colour according to number of steps
- R (j, k)=l;
- end
- end
- % coloristic map
- %colormap (hot);
- colormap ('default');
- brighten (0.5);
- % function displays matrix R as an image
- % value of point (i,j) is the color of this point on the graph
- imagesc (R);
- colorbar;
- % turning off the backround, signatures etc.
- axis off;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement