%Integrate the traveling wave equations for reource consumption model
 function rescon
 set(0,                           ...
   'defaultaxesfontsize', 20,   ...
   'defaultaxeslinewidth', 1.0, ...
   'defaultlinelinewidth', 1.2, ...
   'defaultpatchlinewidth', 0.7);
global d c

cmykflg=0;
%if cmykflg=1, this code will make cmyk figure files
%cmykflg = 1;


d = 20;
c = 2;

% start near (1,0,0) on the unstable manifold
lam = (-c+sqrt(c^2+4*d))/(2*d);
eps = 0.001;
U0 = 1-eps;
G0 = eps*lam*(c+lam);
W0 = -eps*lam;
 
tstep = 1;
t_end = 100;
 
%specify the output points
tspan = [0:tstep:t_end];

s0 = [U0;G0;W0];
 

[T,S] = ode23(@deRHS,tspan, s0 );  
U = S(:,1);
G = S(:,2);
W = S(:,3);
 
 
figure(1)
plot3(U,G,W)
 
xlabel('U','fontsize',20)
ylabel('S','fontsize',20)
zlabel('W','fontsize',20)

figure(2)
plot(T,U,T,G,T,W,T,zeros(1,length(T)),'--','linewidth',2)
xlabel('\xi','fontsize',20)
legend('U','S','W','fontsize',16)

if(cmykflg==1)
    print('../../figs_c/chapt_6/res_cons_prfle','-deps','-cmyk')
 end

end

%the right hand side for ode simulation:
function s_prime=deRHS(t,s)
global d c

u = s(1);
g = s(2);
w = s(3);


Fu = w;
Fg = (c-w-c*(u+g))/d;
Fw = -c*w-u*g;
 
s_prime = [Fu Fg Fw]';

end
