Solving the Wave Equation with Dirichlet boundary conditions

Apply the initial condition in problem 2 on the worksheet

f[x_]:=Piecewise[{{x,0<x<1},{2-x,1<x<2}}]

First compute the Fourier coefficients:

Simplify[Integrate[f[x] Sin[n π x/2],{x,0,2}],Assumptions->n∈Integers]

Now plot the solution:

Manipulate[
Plot[Sum[(8/((n^2) (π^2)))Sin[((n π)/2)]Sin[((n π)/2)x]Cos[((n π)/2)t],{n,1,50}],{x,0,2},PlotRange->{-1,1},AxesLabel->Automatic],
{t,0,10}
]

Apply the initial condition in problem 3 on the worksheet

f[x_]:=Piecewise[{{x-1,1<x<3/2},{2-x,3/2<x<2},{0,True}}]

Compute the Fourier coefficients:

Simplify[(2/3) Integrate[f[x] Sin[n π x/3],{x,0,3}],Assumptions->n∈Integers]

a[n_]:=-((6 (Sin[((n π)/3)]-2 Sin[((n π)/2)]+Sin[((2 n π)/3)]))/((n^2) (π^2)))

Table[a[n],{n,1,10}]

Now plot the solution:

Manipulate[
Plot[Sum[a[n]Sin[((n π)/3)x]Cos[((n π)/3)t],{n,1,50}],{x,0,3},PlotRange->{-1,1},AxesLabel->Automatic],
{t,0,10}
]