<< fem.m

y1[x_]:=Sin[Pi x];
-y1''[x]+y1[x]//Simplify

f1[x_]:=(1+(π^2)) Sin[π x]

{aa,bb,nn} = {0,1,5};
grid = Table[aa+ii/nn (bb-aa),{ii,0,nn}]

?basisVec

allbf = basisVec[grid,x];

Plot[allbf,{x,aa,bb},PlotStyle->{Thick}]

?FEMSolve

u1=FEMSolve[{f1,1,1},grid,x,{0,0}];

u1

Plot[{y1[x],u1},{x,aa,bb},PlotStyle->{{Thick,Blue},{Thick,Red}}]

{aa,bb,nn} = {-1,1,5};
grid = Table[aa+ii/nn (bb-aa),{ii,0,nn}]

y2[x_]:=(1/2 Sqrt[2-2x])^3;
-y2''[x]+y2[x]//Simplify

f2[x_]:=((1-8 x+4 (x^2))/(8 (Sqrt[2-2 x])))

u2=FEMSolve[{f2,1,1},grid,x,{1,0}];

Plot[{y2[x],u2},{x,aa,bb},PlotStyle->{{Thick,Blue},{Thick,Red}}]

y3[x_]:=Cos[Pi x]^2-x
Simplify[-y3''[x]+2 y3[x]]

f3[x_]:=1-2 x+(1+2 (π^2)) Cos[2 π x]

{aa,bb,nn}={0,1,10};
grid = Table[aa+ii/nn(bb-aa),{ii,0,nn}];

u3=FEMSolve[{f3,1,2},grid,x,{1,0}];

Plot[{y3[x],u3},{x,aa,bb},PlotStyle->{{Thick,Blue},{Thick,Red}}]