
% Working demo of merging the zviz plot with the Newton itteration

% To show the limit cycle start at: s=2 \pm 1.5i; OR s=2+1.4j
% for this starting value, a step size of 0.9 removes the limit cycle
% even stepsize of 0.99 jumps out of the limit cycle after a few steps

clc
close all;
clear all;
figure(18);


%zviz W(S)=(S.^5 -S -1)./(5*S.^4 -1)
%print -depsc2 'Quartic.png'

% quartic.png needs to be a color png file (use quartic.txt(.m) to create it)
%the y and x data values for perfection may depend on labels
%imshow('quartic.png', 'xdata',[-3.3, 3.3], 'ydata',[-2.4, 2.5]'); %y perfect; x is slightly off
%imshow('quartic.png', 'xdata',[-3.5, 3.3], 'ydata',[-2.4, 2.5]'); %x,perfect y close
imshow('quartic.png', 'xdata',[-3.5, 3.3], 'ydata',[-2.4, 2.55]'); %x, y perfect

set(gcf,'defaultAxesFontSize',18)

axis([-2, 2, -2, 2]);  %#1
axis on; grid on; hold on;
Col='-ko'; %starting color

Stepsize=0.1;
alpha=input('Stepsize= ');

while Stepsize~=0

n=1;
y=[];
s0= 1+0.75j
s0=input('Imag part s0 =');
s=1+j*s0
disp(sprintf('Starting value =1 + j%g',imag(s)));

while n <= 50 
  y(n)=s;
  %P = [1 0 0 0 -1 -1] %Coefs of 5th degree poly
L=-(s^5 -s -1)/(5*s^4 -1);
s = s +alpha*L;
%% disp(sprintf('L=(%g,%g); s=(%g,%g)',real(L),imag(L), real(s),imag(s)));
%input('hit key to continue');
%pause(0.1);
plot(real(y)-j*imag(y),Col,'linewidth',2,'markersize',7);
if(abs(L)<1e-6);break;end; %terminate the itteration
n=n+1;
end

s=y(end);
disp('');
disp(sprintf('L=(%g,%g); s=(%g,%g)',real(L),imag(L), real(s),imag(s)));
%title(sprintf('n=%d;   S_0= %g+%gj',n-1,1,j*imag(s0)),'fontsize',18);
print -depsc2 'ZvizDemo'
%reset color and linetype
Col='-go';
end %while
