% Right hand side in function Fu,
% differential in function dFu, second in d2Fu.
% Critical points are (x1,x2)=(n*pi,0).
% They are hyberbolic: unstable for n even and asymptotically
% stable for n odd.

global c k;
k=1;c=1/4;

% draw two trajectories, the first one startin near unstable pi
% and the second starting near stable 2*pi

for i=1:2,

n=i;
num=25;
crit=[n*pi,0];
[V,D]=eig(dFu(1,crit))

ini=[n*pi-.1*n n];
interv=[0,num];
func='Fu';
ode23(func,interv,ini,odeset('OutputFcn','odephas2'))

hold on

end;

axis image
set(gca,'FontSize',15)
xlabel('x1','FontSize',20)
ylabel('x2','FontSize',20)
hold off

% this can now be used to plot as many different trajectories one wishes

% it seems I forgot to do part d) of this. coming up.

% Direction field m-file (script) 
% Source: Bäckström: Praktisk matematik med Matlab
%clear variables; hold off;
%xmax=4; ymax=3; delx=xmax/30; dely=ymax/30;   % *** problem dependent
%[X,Y]=meshgrid(0:delx:xmax,0:dely:ymax);
%  DX=ones(size(X));  % Unit x-xomponents of arrows
%  DY=fode1(X,Y);      % Slopes, *** Change the name 'fode' to your m-file name
%  L=sqrt(DX.^2+DY.^2); % Initial lengths
%  DX1=DX./L; DY1=DY./L; % Unit length for all arrows
%figure(1); quiver(X,Y,DX1,DY1,'.'); grid on;  % The period ('.') suppresses
%                                               % arrowheads
%figure(1); quiver(X,Y,DX1,DY1); grid on;       % Include arrowheads
%  axis([0 xmax 0 ymax]); title('Direction field');
