f[x_]:=x^3+6*x^2+1
n=9;
a=0;
b=2;
ya=1;(*dirichletova podm*)
yb=5;(*dirichletova podm*)
a0=-1;(*koeficienty*)
a1=0;(*koeficienty*)
a2=1;(*koeficienty*)
presneriesenie[x_]:=8.286134462*Exp[x]+5.713865537*Exp[-x]-
x^3-6*x^2-6*x-13

Okrajul[n_,xleft_, xright_, Leftbv_,
Rightbv_,a0_,a1_,a2_,f_,pres_ ]:=
Module[{h,a,b,c,ps2,ddiag, diag,hdiag,
 riesenie},
h=N[(xright-xleft)/(n+1)];
a=N[a0-2*a2/h^2];
b=N[a2/h^2+a1/(2*h)];
c=N[a2/h^2-a1/(2*h)];
Print[h];
Print[a];
Print[b];
Print[c];
ps2=Join[{f[xleft+h]-c*Leftbv},
Table[f[xleft+i*h],{i,2,n-1}],
{f[xleft+n*h]-b*Rightbv}];
hdiag=Table[b,{n-1}];
diag=Table[a,{n}];
ddiag=Table[c,{n-1}];
m=SparseArray[{Band[{1,2}]->hdiag,
Band[{1,1}]->diag,Band[{2,1}]->ddiag},
{n,n}];
MatrixForm[Normal[m]];
Print[" matica"];
Print[MatrixForm[Normal[m]]];
Print["prava strana"];
Print[ps2];
riesenie=LinearSolve[m,N[ps2]];
xs=Table[xleft+(i-1)*h,{i,1,n+2}];
ys=Join[{Leftbv},
Table[riesenie[[i]],{i,1,n}],
{Rightbv}];
graf=Table[{xs[[i]],ys[[i]]},
{i,1,n+2}];
vysledky=
Table[{xs[[i]],ys[[i]],pres[xs[[i]]],
Abs[(ys[[i]]-pres[xs[[i]]])]},
{i,1,n+2}];
](*a,b,c vzniknu z diskretizacie, h-krok *)

Okrajul[n,a,b,ya,yb,a0,a1,a2,f,
presneriesenie]

g1=Plot[presneriesenie[x],{x,a,b},
PlotRange->All,
PlotStyle->RGBColor[0,1,0]];

g2=ListPlot[graf,PlotRange->All,
PlotStyle->{PointSize[0.02],
RGBColor[1,0,1]}];

Show[g1,g2]

Print[" hodnota x num.ries pres. ries
odchylka"]
PaddedForm[TableForm[vysledky],{5,4}]