%modes.m Illustration of modes
% kja 060812

aminit;					

% Define a second order system for the example
k0=0.1;k1=0.1;k2=0.5;b0=1.5;
A=[-k0-k1 k1;k2 -k2];B=[b0;0];C=[1 0;0 1];
sys = ss(A, B, C, 0);

% Compute the modes and mode shapes
[V,D]=eig(A);
x1=V(:,1);
x2=V(:,2);

% Generate a phase plot for the system
figure(1); clf; subplot(221); hold on;
amaxis([-1 1 -1 1]); set(gca, 'DataAspectRatio', [1 1 1]);
amphaseplot('linsys2', ...
  'timepts', [0.5 1.5 3], nan, ...
  [-1 0; -1 0.5; -1 1; -0.75 1; -0.5 1; 0 1; 0.25 1; 0.5 1; ...
    1 0.5; 1 0; 1 -0.5; 1 -1; 0.75 -1; 0.5 -1; 0 -1; -0.25 -1; -0.5 -1;], ...
  0:0.1:8, A(1,1), A(1,2), A(2,1), A(2,2));

% Add eigenvectors
plot(2*[-x1(1) 0 x1(1)], 2*[-x1(2) 0 x1(2)], 'r-', ...
  'LineWidth', AM_thick_linewidth);
plot(2*[-x2(1) 0 x2(1)], 2*[-x2(2) 0 x2(2)], 'r-', ...
  'LineWidth', AM_thick_linewidth);

xlabel('x1'); ylabel('x2', 'Rotation', 0);
amtext(-0.3, 0.75, 'Fast', 'BackgroundColor', [1 1 1]);
amtext(-0.9, -0.78, 'Slow', 'BackgroundColor', [1 1 1]);
amprint('modes-phase.eps');

% Time domain simulations
figure(2); clf;
t=0:0.1:50;
u=zeros(size(t));
y1=lsim(sys,u,t,x1);
y2=lsim(sys,u,t,x2);
subplot(421)
pl=plot(t,y1(:,1),'b',t,y1(:,2),'r--');
set(pl,'Linewidth', AM_data_linewidth);
amaxis([0 50  0 1]);
amtext(8, 0.75, 'Slow mode');
lgh = legend('x1', 'x2'); legend(lgh, 'boxoff');
ylabel('x1x2')

subplot(423)
pl=plot(t,y2(:,1),'b',t,y2(:,2),'r--');
set(pl,'Linewidth', AM_data_linewidth);
amaxis([0 50  -0.2 1]);
amtext(8, 0.7, 'Fast mode');
ylabel('x1x2')
xlabel('t');

amprint('modes-time.eps');

% Local Variables:
% mode: Matlab
% End:
