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 >
clear;
t = 0:0.02:40;
global mu = 1.0;
global k = 2.0;
function dy_dt = f(y, t)
global mu;
global k;
dy_dt = zeros (2,1);
dy_dt(1) = y(2);
dy_dt(2) = mu .* (1-y(1).^2) .* y(2) - k .* y(1);
endfunction
y2_init = 2.0;
y1_init = 1.0;
y0 = [y2_init y1_init];
y = lsode ("f", y0, t);
hFig = figure(1);
subplot(1,5,[1 2 3]);
plot(t,y(:,1),'r-','LineWidth',2,t,y(:,2),'b-','LineWidth',2);
xlabel('time');
xlim([0 t(end)]);
ylim([-8 8]);
legend('y2(t)','y1(t)');
grid on;
subplot(1,5,[4 5]);
plot(y(:,1),y(:,2),'r-','LineWidth',2);
xlabel('y(2)');ylabel('y(1)');
axis([-8 8 -8 8]);
pbaspect([1 1 1]);
tStr = sprintf("y1(0)=%0.2f,y2(0)=%0.2f \nmu=%0.2f,k=%0.2f",y1_init,y2_init,mu,k);
title(tStr);
set(hFig,'Position',[300 300 780 300]);
|