L=1.0 Pi
pb=5
h=L/pb;

grid=Range[h,L-h,h];

faces=Range[h/2.0,L-h/2.0,h];

A=SparseArray[
{

{i_,i_} -> 2/h,
{i_,j_}/;(i-j)==1 -> -1/h,
{i_,j_}/;(i-j)==-1 -> -1/h

},{pb-1,pb-1}]

A[w_,e_]:=SparseArray[
{
{i_,i_} -> ((1+e)*(1+w))/h,
{i_,j_}/;(i-j)==1 -> -(1+w)/h,
{i_,j_}/;(i-j)==-1 -> -(1+e)/h
},{pb-1,pb-1}]

f[x_]:=Sin[x]

B=Table[Table[0,{j,1,pb-1}],{i,1,pb-1}];

For[i=1,i<pb,i++,
{
For[j=1,j<pb,j++,
{
(*Print[i,"   " ,j,"   ",faces[[j]],"    ",faces[[j+1]]];*)
B[[i,j]]=A[faces[[j]],faces[[j+1]]][[i,j]];
}]
}
]

A//MatrixForm
A=Prepend[A,Prepend[Table[0,{i,1,pb-2}],1]]
A//MatrixForm
A=Append[A,Append[]]

b= h*f[grid]

b=Prepend[b,10]
b

solver=LinearSolve[A]

solution=solver[b]

ListLinePlot[Transpose[{grid,solution}]]

b-B.solution;

B//MatrixForm

solver=LinearSolve[B]

b

L=1.0 Pi
pb=50
h=L/pb;
grid=Range[h,L-h,h];
faces=Range[h/2.0,L-h/2.0,h];
A[w_,e_]:=SparseArray[
{
{i_,i_} -> ((1+e)*(1+w))/h,
{i_,j_}/;(i-j)==1 -> -(1+w)/h,
{i_,j_}/;(i-j)==-1 -> -(1+e)/h
},{pb-1,pb-1}]
f[x_]:=x

B=Table[Table[0,{j,1,pb-1}],{i,1,pb-1}];
For[i=1,i<pb,i++,
{
For[j=1,j<pb,j++,
{
(*Print[i,"   " ,j,"   ",faces[[j]],"    ",faces[[j+1]]];*)
B[[i,j]]=A[faces[[j]],faces[[j+1]]][[i,j]];
}]
}
]
b= h*f[grid]

solver=LinearSolve[B]

solution=solver[b]

ListLinePlot[Transpose[{grid,solution}]]

L=1.0 Pi
pb=5
h=L/pb;
grid=Range[h,L-h,h];
faces=Range[h/2.0,L-h/2.0,h];
A=SparseArray[
{
{i_,i_}/;i==1->1,
{i_,j_}/;(i==1)&&(j>1)->0,
{i_,i_}/;(i==pb+1)->1,
{i_,j_}/;(i==pb+1)&&(j>1)->0,
{i_,j_}/;(i>1)&&(j==1)->0,
{i_,j_}/;(i>1)&&(j==pb+1)->0,
{i_,i_} -> 2/h,
{i_,j_}/;(i-j)==1 -> -1/h,
{i_,j_}/;(i-j)==-1 -> -1/h


},{pb+1,pb+1}]
f[x_]:=Sin[x]
A//MatrixForm

L=1.0 Pi
pb=5
h=L/pb;
grid=Range[h,L-h,h];
faces=Range[h/2.0,L-h/2.0,h];
A=SparseArray[
{
{i_,i_} -> 2/h,
{i_,j_}/;(i-j)==1 -> -1/h,
{i_,j_}/;(i-j)==-1 -> -1/h
},{pb-1,pb-1}]
f[x_]:=x
A//MatrixForm

grid=Range[h,L-h,h]
grid=Prepend[grid,0]
grid=Append[grid,L]

b= h*f[grid]

b=Prepend[b,10]
b=Append[b,10]

solver=LinearSolve[A]

solution=solver[b]

ListLinePlot[Transpose[{grid,solution}]]