MATH529: Lesson23, Vibrating string

xPluck=0.25;
f[x_] := If[x<xPluck,x/xPluck,(1-x)/(1-xPluck)];
Plot[f[x],{x,0,1}]

nMax=40;
b=Table[(1/0.5)NIntegrate[f[x] Sin[π n x],{x,0,1}],{n,1,nMax}]

y[x_,nM_]:=Sum[ b[[n]] Sin[π n x],{n,1,nM}]

Manipulate[Plot[{y[x,n],f[x]},{x,0,1}],{n,1,nMax,1}]

u[t_,x_,nM_]:=2Sum[ b[[n]] Sin[π n x] Cos[π n t],{n,1,nM}]

Animate[Plot[u[t,x,23],{x,0,1},Axes->False,Frame->True,PlotRange->{{0,1},{-1,1}}],{t,0,10}]