clear

% y'=x^2, y(0)=1
x0=0;
y0=1;
h=.1;
N=round(10/h);
f=@(x,y) x.^2;
[x,y]=EulersMethodFn(x0,y0,h,N,f);

truesoln=x.^3/3+1;
figure;plot(x,truesoln,'k',x,y,'r')
legend('True','Euler')

% y'=2*x*y, y(0)=1
x0=0;
y0=1;
h=.1;
N=round(1/h);
f=@(x,y) 2*x*y;
[x,y]=EulersMethodFn(x0,y0,h,N,f);

truesoln=exp(x.^2);
figure;plot(x,truesoln,'k',x,y,'r')
legend('True','Euler')

% error in Euler's method for this h at x=1
y(end)-truesoln(end)