%solve y'=1/t^2-y/2-y^2;  1<=t<=2,y(1)=-1
%Euler method
a=1;b=2; %interval
N=10001;    %numer of nodes
h=(b-a)/(N-1); % step size
y=zeros(N,1);
t=a:h:b;
y(1)=-1;% initial condition

for i=1:N-1
    y(i+1)=y(i)+h*funEx1(t(i),y(i));
end
 [T,Y]=ode45('funEx1',[a,b],-1);
 plot(t,y,'r')

y_exact=-1./t;
hold on
plot(t,y_exact,'k')
plot(T,Y,'.r')
y(N)
Y(length(T))
err_rel=abs(y(N)-y_exact(N))/abs(y_exact(N))