syms y(x) x L Y
q(x) = 2*cos(pi*x/L);
Dy = diff(y);
D2y = diff(Dy);
ODE = D2y + q
[VF,Subs] = odeToVectorField(ODE)
bvpfcn = matlabFunction(VF, 'Vars',{x,Y,L})
I solved it completely, however I do not want to deprive you of the same feeling of accomplishment, so I leave the rest to you. It is a straightforward solution. Follow the examples in the documentation I linked to.
.