
% MATLAB code

% - - - - - - - - - - - - - - - - - - - -
% solve a system of two equations
% plot the phase portrait
% - - - - - - - - - - - - - - - - - - - -

% define the set of time instances for plotting data points
times = 0:0.1:5;

hold on

% use a set of initial conditions
for x0=-3:3
[time, xy] = ode45('node_func',times,[x0 3]);
plot(xy(:,1),xy(:,2),'-b')
end

for x0=-4:3
[time, xy] = ode45('node_func',times,[x0 -3]);
plot(xy(:,1),xy(:,2),'-b')
end

% format the graph
xmin = -3; xmax = 3;
ymin = -3; ymax = 3;
axis([xmin xmax ymin ymax]);
axis equal;
box on;
xlabel('x','FontSize',18);
ylabel('y','FontSize',18);
set(gca,'XTick',xmin:1:xmax,'FontSize',18);
set(gca,'YTick',ymin:1:ymax,'FontSize',18);

hold off

% print the graph
%print('-depsc','dynsys')



% function for a system of equations
function rhs = node_func( t, xx )

x1 = xx(1);
x2 = xx(2);

xdot = x1-2*x2;
ydot = 3*x1-4*x2;

rhs = [xdot; ydot];

end