% Rudder curve and simulation of the unstable tanker
%   kja 070817
aminit;
tankerpar;
%a1=-0.6;a2=-0.3;a3=-5;a4=-2;al=-2;b1=0.1;b2=-0.8;
%a1=-0.9;a2=-1.5;a3=-1;a4=-1;al=-0.5;b1=0.1;b2=-1;
v=-0.5:0.01:0.5;
d=((a1*a4-a2*a3)*v+al*a4*v.*abs(v))/(b2*a2-b1*a4);
r=-(a3*v+b2*d)/a4;
clf;figure(1);subplot(221)
pl=plot(d,r,'b-');
set(pl,'Linewidth', AM_data_linewidth);
amaxis([-0.1 0.1 -0.4 0.4]);

xlabel('delta');ylabel('r');
amprint('-depsc', 'ruddercurve.eps');
%
%   Simulation of ship motion
ts=300;tspan=[0,ts];
x01=[0;0;0;0;0];x02=[0;0;0;0.1;0];x03=[0;0.01;0;-0.1;0];
str='b--';
clf;figure(2);subplot(221)
for x0=[x01 x02 x03],
[t,x]=ode45('tanker',tspan,x0);
pl=plot(x(:,1),x(:,2),str);hold on;
set(pl,'Linewidth', AM_data_linewidth);ylabel('y');xlabel('x');
amaxis([0 40 -20 20]);axis square;
str='b';
end
amprint('-depsc', 'tanker-traj.eps');