Clear[u,v,dv,x]
ψ[x_]=Piecewise[{{1+x,-1≤x≤0},{1-x,0<x≤1}},0];
θ[x_]=Piecewise[{{1,-1≤x≤0},{-1,0<x≤ 1}},0];
n=10; h=1/10; p=1; q=2; 
f[x_]=Sin[π x];
Plot[{θ[x],ψ[x],ψ[x-1]},{x,-2,2},PlotStyle->Thick]

v[x]=Table[ψ[x/h-i],{i,1,n-1}];
dv[x]=Table[θ[x/h-i]/h,{i,1,n-1}];
Plot[Evaluate[v[x]],{x,0,1},PlotRange->All]

s=DSolve[{-p y''[x]+q y[x]==f[x],y[0]==0,y[1]==0},y[x],x];

A=Table[
Integrate[p*dv[x][[i]]*dv[x][[j]]+q*v[x][[i]]*v[x][[j]],{x,0,1}],{i,1,n-1},{j,1,n-1}];
B=N[Integrate[v[x]*f[x],{x,0,1}]];
U=LinearSolve[A,B];
Plot[Evaluate[{y[x]/.s,U.v[x]}],{x,0,1}]

Clear[u,v,dv,x,p,q]
ψ[x_]=Piecewise[{{1+x,-1≤x≤0},{1-x,0<x≤1}},0];
θ[x_]=Piecewise[{{1,-1≤x≤0},{-1,0<x≤ 1}},0];
n=10; h=1/10; p[x_]=1; q[x_]=Sin[Pi x]; 
f[x_]=x^2(1-x);
Plot[{θ[x],ψ[x],ψ[x-1]},{x,-2,2},PlotStyle->Thick]

v[x]=Table[ψ[x/h-i],{i,1,n-1}];
dv[x]=Table[θ[x/h-i]/h,{i,1,n-1}];
Plot[Evaluate[v[x]],{x,0,1},PlotRange->All]

s=NDSolve[{-p[x] y''[x]+q [x]y[x]==f[x],y[0]==0,y[1]==0},y[x],x];

A=Table[
Integrate[p[x]*dv[x][[i]]*dv[x][[j]]+q[x]*v[x][[i]]*v[x][[j]],{x,0,1}],{i,1,n-1},{j,1,n-1}]//N
B=N[Integrate[v[x]*f[x],{x,0,1}]]//N
U=LinearSolve[A,B]
Plot[Evaluate[{y[x]/.s,U.v[x]}],{x,0,1}]