u0=0;
un=0;
n = 10;
h=1/n;
(*vytvorenie siete bodov*)
g[x_]=x^2;
x=Table[i,{i,0,1,h}];
(*vytrvorenie pravej strany*)
(a=
Table[
If[i==j,2,
If[i==j+1,-1,
If[i==j-1,-1,0]]],
{i,1,n},
{j,1,n}])//MatrixForm;
a[[n,n-1]]=-2;

b=
Table[
If[l==1,h^2*g[x[[l+1]]]+u0,
If[l==n,h^2*g[x[[l+1]]+un *2*h],
h^2*g[x[[l+1]]]]],{l,1,n}];
r= LinearSolve[a,b];
r= Prepend[r,u0];
a//MatrixForm
(*r = Append[r,un]*)
(*ListPlot[Table[x[i],r[i],*)

Riesenie=Table[{x[[z]],r[[z]]},{z,n+1}];
G1 = ListPlot[{Riesenie}, Joined->True];
vysl= DSolve[{-y''[k]==g[k],y[0]==u0,y'[1]==un},y[k],k]

G2 =Plot[y[k]/.vysl,{k,0,1},PlotStyle->Red,PlotRange->{Automatic,{0,1}}];
Show[ G2 , G1]