u0=0.1;
un=0.1;
n = 5;
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-1},{j,1,n-1}])//MatrixForm;
b=Table[If[l==1,h^2*g[x[[l+1]]]+u0,If[l==n-1,h^2*g[x[[l+1]]]+un,h^2*g[x[[l+1]]]]],{l,1,n-1}];
r= LinearSolve[a,b];
r =Append[r,un];
r= Prepend[r,u0]
(*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]