(*riesime system -u``(x)=g(x)
g(x)=x^2
s op u(0)=0;u(1)=0
*)

a=0;
b=1;
n=5;
h=(b-a)/n
g[x_]:=x^2;
u0=0;
u1=0;

(*vytvorenie siete bodov*)
x=Table[i,{i,0,1,h}]
(A=Table[Table[If[j==i,2,If[j==i-1,-1,If[j==i+1,-1,0]]],{j,1,n-1}],{i,1,n-1}])//MatrixForm
b=Table[h^2*g[x[[i]]],{i,2,n}]

R=LinearSolve[A,b]

R=Append[R,0]
R=Prepend[R,0]

R

Ries=Table[{x[[i]],R[[i]]},{i,1,6}]

r2=ListPlot[Ries]

DSolve[{u''[k]==-k^2,u[0]==0,u[1]==0},u,k]

r1=Plot[(1/12) (k-(k^4)),{k,0,1}]

Show[r1,r2]

(*riesime system -u``(x)=g(x)
g(x)=x^2
s op u(0)=1;u(1)=-1
*)

a=0;
b=1;
n=5;
h=(b-a)/n
g[x_]:=x^2;
u0=1;
u1=-1;

x=Table[i,{i,0,1,h}]
(A=Table[Table[If[j==i,2,If[j==i-1,-1,If[j==i+1,-1,0]]],{j,1,n-1}],{i,1,n-1}])//MatrixForm
b=Table[If[i==1,h*h*g[i]+u0,If[i==n-1,h*h*g[i]+u1,h*h*g[i]]],{i,1,n-1}]


R=LinearSolve[A,b]
R=Prepend[R,u0];
R=Append[R,u1];


Ries=Table[{x[[i]],R[[i]]},{i,1,6}];
r2=ListPlot[Ries];
r1=Plot[(1/12) (12-23 k-(k^4)),{k,0,1}];
Show[r1,r2]

A
x
b

(*riesime system -u``(x)=g(x)
g(x)=x^2
s op u(0)=0;u'(1)=0
*)

DSolve[{u''[k]==-k^2,u[0]==1,u[1]==-1},u,k]