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

(* algoritmus vypoctu *)
Okraju1[n_,xleft_,xright_,Leftbv_,Rightbv_,a0_,a1_,a2_,f_,pres_]:=Module[{h,a,b,c,ps,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)];
ps=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]];
riesenie=LinearSolve[m,N[ps]];
Print[" matica"];
Print[MatrixForm[Normal[m]]];
Print[" prava strana"]; 
Print[ps];
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}];
]

Okraju1[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->RGBColor[0,0,1]];
Show[g1,g2]

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

(* priklad ked acka su funkcie*)

f[x_]:=x^2*(Sin[x]-Cos[x])-2*x*Sin[x];
n=20;
a=0;
b=π;
ya=0;
yb=-π;
a0[x_]:=1;
a1[x_]:=-x;
a2[x_]:=x;
presneriesenie[x_]:=x*Cos[x];

Okraju1[n_,xleft_,xright_,Leftbv_,Rightbv_,a0_,a1_,a2_,f_,pres_]:=Module[{h,a,b,c,ps,ddiag,diag,hdiag,riesenie},
h=N[(xright-xleft)/(n+1)];
ps=Join[
{f[xleft+h]-(a2[xleft+h]/h^2-a1[xleft+h]/(2*h))*Leftbv},Table[f[xleft+i*h],{i,2,n-1}],{f[xleft+n*h]-(a2[xleft+n*h]/h^2+a1[xleft+n*h]/(2*h))*Rightbv}
];
hdiag=Table[a2[xleft+i*h]/h^2+a1[xleft+i*h]/(2*h),{i,1,n-1}];
diag=Table[a0[xleft+i*h]-2*a2[xleft+i*h]/h^2,{i,1,n}];
ddiag=Table[a2[xleft+i*h]/h^2-a1[xleft+i*h]/(2*h),{i,2,n}];
m=SparseArray[{Band[{1,2}]->hdiag,Band[{1,1}]->diag,Band[{2,1}]->ddiag},{n,n}];
MatrixForm[Normal[m]];
riesenie=LinearSolve[m,N[ps]];
Print[" matica"];
Print[MatrixForm[Normal[m]]];
Print[" prava strana"]; 
Print[ps];
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}];
]

Okraju1[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->RGBColor[0,0,1]];
Show[g1,g2]