Triangle Standing Wave

Remove["Global`*"]

Adapted from Figures 5.4 and 5.5

Make it clear that that the parameters are positive, real numbers

$Assumptions={L>0,v>0,A>0};

Pick some default values for the string length, velocity, and amplitude

vals={L->4,v->1,A->3};
xMax=L/.vals;

Define the initial shape

initialShape=A Piecewise[{{2x/L,x<L/2},{2(1-x/L),x>L/2}}];

Plot it to make sure it looks right

triangle=Plot[initialShape/.vals,{x,0,xMax},
PlotStyle->{Black,Thick},LabelStyle->15]

Find the Fourier Coefficients

nMax=10;
nVals=Range[nMax];

Bn=(2/L)Integrate[initialShape Sin[nVals Pi x/L],{x,0,L}]

Plot the approximation over the function

approx=Total[Bn Sin[nVals Pi x/L]];
Show[
triangle,
Plot[approx/.vals,{x,0,xMax},PlotStyle->{Red,Thick}]
]

Form the full solution and plot for a few fractions of the fundamental period

u=Total[Bn Sin[nVals Pi x/L] Cos[nVals Pi v t/L]];

period=2L/v;

uZero=u/.t->0/.vals;
uEighth=u/.t->period/8/.vals;
uThird=u/.t->period/3/.vals;
uHalf=u/.t->period/2/.vals;

Plot[{uZero,uEighth,uThird,uHalf},{x,0,xMax},
LabelStyle->15,
PlotStyle->{
{Black,Thick},
{Blue,Thick},
{Green,Thick},
{Red,Thick}}]

Animate the full solution

uLim=1.05A/.vals;

tMax=2period/.vals;

Animate[
Plot[u/.vals/.t->time,{x,0,xMax},
PlotRange->{-uLim,uLim},
PlotStyle->{Black,Thick},LabelStyle->15],
{time,0,tMax},AnimationRunning->False]