u[x_,t_]:=Sum[
Sin[((n π x)/L)]c[n]Cos[((n π v t)/L)],
{n,1,20}]

u[x,0]

c[n_]:=((8 k)/((n^2) (π^2)))Sin[n π/2]

L=2;v=1;k=0.1;

Plot[u[x,0],{x,0,L}]

Plot3D[u[x,t],{x,0,L},{t,0,10},PlotPoints->50]

Animate[
Plot[u[x,t],{x,0,L},PlotRange->{-0.5,0.5}],
{t,0,4}]

c2[n_]:=Evaluate[2/L Integrate[
((4k)/L)x Sin[n π x/L],{x,0,L/4}]+
2/L  Integrate[-((4 k)/L)(x-L/2)Sin[n π x/L],{x,L/4,L/2}]]

c2[1]