f[x_,y_]:=x*y^2
h=0.07;
x0=0;
y0=1;
koniec=1;

RK[x_,y_,f_,h_]:=Module[{k1,k2,k3,k4,riesenie},
k1=f[x,y];
k2=f[x+h/2,y+h*k1/2];
k3=f[x+h/2,y+h*k2/2];
k4=f[x+h,y+h*k3];
riesenie=y+h*(k1+2*k2+2*k3+k4)/6]

Pres[x_]:=2/(2-x^2)
x[0]=x0;
y[0]=y0;
n=koniec/h;

Do[{x[i]=x0+i*h,y[i]=RK[x[i-1],y[i-1],f,h]},{i,1,n,1}]
data=Table[{x[i],y[i]},{i,0,n}];
data1=Table[Abs[{y[i]-Pres[x[i]]}],{i,0,n}]

vysledky=Table[{x[i],y[i],Pres[x[i]],Abs[{y[i]-Pres[x[i]]}]},{i,0,n}]
maxerror=Max[data1]

Print["        hodnota x    numericke riesenie   presne riesenie    odchylka "]
PaddedForm[TableForm[vysledky],{12,4}]

g=Plot[Pres[x],{x,0,1},PlotStyle->{RGBColor[1,0,0],Thickness[0.005]}];
graf1=ListPlot[data,PlotStyle->{RGBColor[0,0,1],Thickness[0.005]},Joined->True];Show[g,graf1]

f[x_,y_]:=x*y^2
h=0.07;
x0=0;
y0=1;
koniec=1;

RK[x_,y_,f_,h_]:=Module[{k1,k2,k3,k4,riesenie},
k1=f[x,y];
k2=f[x+h/2,y+h*k1/2];
k3=f[x+h/2,y+h*k2/2];
k4=f[x+h,y+h*k3];
riesenie=y+h*(k1+2*k2+2*k3+k4)/6]

Pres[x_]:=2/(2-x^2)
x[0]=x0;
y[0]=y0;
n=koniec/h;

Do[{x[i]=x0+i*h,y[i]=RK[x[i-1],y[i-1],f,h]},{i,1,n,1}]
data=Table[{x[i],y[i]},{i,0,n}];
data1=Table[Abs[{y[i]-Pres[x[i]]}],{i,0,n}]

vysledky=Table[{x[i],y[i],Pres[x[i]],Abs[{y[i]-Pres[x[i]]}]},{i,0,n}]
maxerror=Max[data1]

Print["        hodnota x    numericke riesenie   presne riesenie    odchylka "]
PaddedForm[TableForm[vysledky],{12,4}]

g=Plot[Pres[x],{x,0,1},PlotStyle->{RGBColor[1,0,0],Thickness[0.005]}];
graf1=ListPlot[data,PlotStyle->{RGBColor[0,0,1],Thickness[0.005]},Joined->True];Show[g,graf1]