
tmax=40;nb_pts=100;

deff('[Xdot]=f(t,X)','Xdot=[dyn(t,X(1))-X(2)*X(1);com(t,X)];..
                      if X(1)<0 then Xdot(1)=0;end;..
                      if X(2)<0 then Xdot(2)=0;end;');

if isdef('linearise') then
    if (linearise=='on') then 
       [A,B,f_lin]=tangent('f',[x_e;E]);
    end;
end;

t0=0;t=t0:(tmax/nb_pts):tmax;

xmax=K;

vx=0:(xmax/nb_pts):xmax;
vy=feval(t0,vx,dyn);
hmax=4/3*max(vy);

xset('window',0);
xbasc();
xselect();

plot2d(vx,vy',5,strf='011',rect=[0,0,xmax,hmax]);
xset('line style',2);
plot2d([0,xmax],[0,E*xmax],3,strf='011',rect=[0,0,xmax,hmax]);
plot2d([x_e,x_e],[0,E*x_e],strf='011',rect=[0,0,xmax,hmax]);
xset('line style',1);
xtitle('','x','h');

rep=xclick();

while rep(1)==0
if rep(2)<>0 then..
 X0=[rep(2);rep(3)/rep(2)];
 X=ode(X0,t0,t,f);
 S=[X(1,:);X(2,:).*X(1,:)];
 plot2d(S(1,:),S(2,:),2,strf='011',rect=[0,0,xmax,hmax]);
 if isdef('linearise') then
    if (linearise=='on') then 
      X=ode(X0,t0,t,f_lin);
      S=[X(1,:);X(2,:).*X(1,:)];
      xset('line style',2);
      plot2d(S(1,:),S(2,:),2,strf='011',rect=[0,0,xmax,hmax]); 
      xset('line style',1);
    end;
 end;
 end;
rep=xclick();
end;
