function fig7_4

%  euler method for various M values
%  y' = f(t,y)  with   y(0) = y0 '

%%% this requires the subaxis and parseArgs files

r=10;
t0=0; y0=0.01;
tmax=5;

% calculate exact solution
tt=linspace(t0,tmax,100);
a0=(1-y0)/y0;
for it=1:100
    exact(it)=1/(1+a0*exp(-r*tt(it)));
end

clf
% get(gcf)
set(gcf,'Position', [9 959 745 386])
co = [0 0 1;
    0 0.5 0;
    1 0 0;
    0 0.75 0.75;
    0.75 0 0.75;
    0.75 0.75 0;
    0.25 0.25 0.25];
set(groot,'defaultAxesColorOrder',co)

subaxis(2,1,1,1,'MT',0.014,'MB',0.075,'MR',0.001,'ML',0.025,'P',0.04)
step=3/r;
m=round(tmax/step);
t=linspace(t0,tmax,m+1);
k=t(2)-t(1);
kr=k*r
y_euler=eulers(t,y0,k,m+1);
plot(t,y_euler,'--bo','MarkerSize',7,'LineWidth',1.5)
axis([0 tmax 0 1.5])
hold on
plot(tt,exact,'r','LineWidth',1.5)
text(2.1,0.35,'kr = 3','FontSize',16,'FontWeight','bold')
set(gca,'xtick',[0 1 2 3 4 5])
grid on
box on
ylabel('y-axis')
set(gca,'FontSize',16,'FontWeight','bold')

subaxis(2,1,1,2)
step=1/r;
m=round(tmax/step);
t=linspace(t0,tmax,m+1);
k=t(2)-t(1);
kr=k*r
y_euler=eulers(t,y0,k,m+1);
plot(t,y_euler,'--bo','MarkerSize',7,'LineWidth',1.5)
hold on
plot(tt,exact,'r','LineWidth',1.5)
text(2.1,0.3,'kr = 1','FontSize',16,'FontWeight','bold')
axis([0 tmax 0 1.1])
set(gca,'xtick',[0 1 2 3 4 5])
grid on
box on
xlabel('t-axis')
ylabel('y-axis')
set(gca,'FontSize',16,'FontWeight','bold')

%exportgraphics(gcf,'/Users/mark/Desktop/eulerS.eps')


% right-hand side of DE
function z=f(t,y)
r=10;
z=r*y*(1-y);

% euler method
function ypoints=eulers(t,y0,k,n)
y=y0;
ypoints=y0;
for i=2:n
    yy=y+k*f(t(i-1),y);
    ypoints=[ypoints, yy];
    y=yy;
end










