f[x_, y_] := 
      x*y^2

x0 = 0;
y0 = 1;
koniec = 1;
h := 0.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)

n = koniec/h;

x[0] = x0
y[0] = y0

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}];

vysledky = 
      Table[{x[i], y[i], Pres[x[i]], Abs[(y[i] - Pres[x[i]])]}, {i, 0, 
          n}]

\(\(\(Print["hodnota_x num.riesenie pres.riesenie  chyba"]

    PaddedForm[TableForm[vysledky], {5, 4}]\)\(\ \)\( (*\ 
      5\ celkove\ 4\ desatinne*) \)\)\)

graf1 = 
      ListPlot[data, 
        PlotStyle -> {RGBColor[0, 0, 1], PointSize[0.02]}]

graf2 = 
      Plot[Pres[x], {x, 0, 1}, 
        PlotStyle -> {RGBColor[0, 1, 0], Thickness[0.01]}]

Show[graf1, graf2]

graf3=ListPlot[data, 
        PlotStyle -> {RGBColor[1, 0, 0], 
            PointSize[0.02]}]

Show[graf1, graf3, graf2]

graf4=ListPlot[data, 
        PlotStyle -> {RGBColor[1, 0, 1], 
            PointSize[0.012]}]

Show[graf1, graf3, graf2, graf4]

h = 0.1;
n = koniec/h;
Do[{x[i] = x0 + i*h, y[i] = Numries[x[i - 1], y[i - 1], f, h]}, {i, 1, 
        n, 1}]
data = Table[{x[i], y[i]}, {i, 0, n}];
vysledky = 
        Table[{x[i], y[i], Pres[x[i]], 
            Abs[(y[i] - Pres[x[i]])]}, 
{i, 0, 
            n}];
Print["krokov: ", n, "   chyba vysla: ", 
      vysledky[[n, 4]]]

    
h = 0.05;
n = koniec/h;
Do[{x[i] = x0 + i*h, y[i] = Numries[x[i - 1], y[i - 1], f, h]}, {i, 1, 
        n, 1}]
data = Table[{x[i], y[i]}, {i, 0, n}];
vysledky = 
        Table[{x[i], y[i], Pres[x[i]], 
            Abs[(y[i] - Pres[x[i]])]}, 
{i, 0, 
            n}];
Print["krokov: ", n, "   chyba vysla: ", 
      vysledky[[n, 4]]]


    
h = 0.001;
n = koniec/h;
Do[{x[i] = x0 + i*h, y[i] = Numries[x[i - 1], y[i - 1], f, h]}, {i, 1, 
        n, 1}]
data = Table[{x[i], y[i]}, {i, 0, n}];
vysledky = 
        Table[{x[i], y[i], Pres[x[i]], 
            Abs[(y[i] - Pres[x[i]])]}, 
{i, 0, 
            n}];
Print["krokov: ", n, "   chyba vysla: ", 
      vysledky[[n, 4]]]

h = 0.1;
Do[{hz = h/j, 
        n = koniec/hz, 
Do[{x[i] = x0 + i*hz, 
            y[i] = RK[x[i - 1], y[i - 1], f, hz]}, {i, 1, n, 
            1}], 
data = 
          Table[Abs[(y[i] - Pres[x[i]])], {i, 0, 
              n}], 
errorx[j] = Max[data]}, {j, 1, 2, 
        1}]

a = errorx[1]
b = errorx[2]
rad = Log[2, a/b]