clear
%x_init=input('Initial state x_init = ')
b=input('Bias vector b = ')
W=input('Weight matrix W = ')
alpha=input('Step size alpha = ')
n_iter=input('Number of iterations n_iter = ')
t=[-1 1];
axis([-1 1 -1 1]);
axis('square')
hold on
xlabel('{\it x}_1','Fontsize',12)
ylabel('{\it x}_2','Fontsize',12)
title('Interactive phase portrait of the BSB net','Fontsize',12)
a1=ones(size(t));
a2=t;
h1=plot(a1,a2,'erasemode','none');
h2=plot(a2,a1,'erasemode','none');
%h5=plot(x_init(1),x_init(2),'o','markersize',6,'erasemode','none');
set(gca,'Fontsize',12)
disp('Pause is in effect; enlarge screen and press any key')
pause
%x=x_init;
%for k=1:n_iter
%   x=max(-1,min(1,x+alpha*(W*x+b)));
%set(h5,'xdata',x(1),'ydata',x(2));
%drawnow
%end
button = 1;		
while(button == 1)   
   [x1,x2,button]=ginput(1);		% Get initial condition using mouse
    x=[x1,x2]';
    xp=x;   
    while (button==1)&( abs(x(1)) < 1 | abs(x(2)) < 1); 
 %     plot(x1,x2,'k.');
      plot(x1,x2,'linestyle','o','markersize',6);
     x=max(min(x+alpha*W*x+alpha*b,1),-1);
 %    plot([xp(1) x(1)],[xp(2) x(2)],'k-',x(1),x(2),'k.');
      plot([xp(1) x(1)],[xp(2) x(2)],'k-',x(1),x(2),'ko','markersize',6);
     xp=x;
   end;   
end;