Followings are the code that I wrote in Octave to creates all the plots shown in this page. You may copy these code and play with these codes. Change variables and try yourself until you get your own intuitive understanding.
< Code 1 >
v = -1:0.2:1;
[y1,y2] = meshgrid(v);
u1=y2;
u2=-y1 - 0.25 .* y2;
function dy_dt = f(y, t)
dy_dt = zeros (2,1);
dy_dt(1) = y(2);
dy_dt(2) = -y(1) - 0.25 .* y(2);
endfunction
y0 = [0.0;1.0];
t = 0:0.2:2.0;
y = lsode ("f", y0, t);
tStr = sprintf("t = %02.1f",t(end));
hFig = figure(1);
subplot(1,2,1);
plot(t,y(:,1),'r-',t,y(:,2),'b-');
xlabel('time');
xlim([0 25]);
ylim([-1 1]);
legend('y2(t)','y1(t)');
title(tStr);
subplot(1,2,2);
hold on;
quiver(y1,y2,u1,u2);
box on;
plot(y(:,1),y(:,2),'r-'); xlabel('y(2)');ylabel('y(1)');
axis([-1 1 -1 1]);
plot(y0(1),y0(2),'bo','MarkerFaceColor',[0 0 1],'MarkerSize',10);
plot(y(end,1),y(end,2),'ro','MarkerFaceColor',[1 0 0],'MarkerSize',10);
title(tStr);
hold off;
set(hFig,'Position',[300 300 780 300]);
|