%solve y'=1/t^2-y/2-y^2;  1<=t<=2,y(1)=-1
%Ruinge Kutta method
a=1;b=2; %interval
N=11;    %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
    K1=funEx1(t(i),y(i));
    K2=funEx1(t(i)+0.5*h,y(i)+0.5*h*K1);
    K3=funEx1(t(i)+0.5*h,y(i)+0.5*h*K2);
    K4=funEx1(t(i)+h,y(i)+h*K3);
    y(i+1)=y(i)+h*(K1+2*K2+2*K3+K4)/6;
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))