Wave Equation

We will use separation of variables to solve
u_t=u_xx
u(0,t)=0
u(L,t)=0
u(x,0)=f(x)
u_t(x,0)=0

Declaration of Constants

L=3;

Initial Position

f[x_]:=Sin[π*x/L]*Sin[10*x]
Plot[f[x],{x,0,L},PlotStyle->Thickness[.01],PlotRange->{{0,L},{-1,1}},PlotStyle->Thickness[.01],AxesLabel->{"x","f(x)"},LabelStyle->Directive[Bold,Black, Large],AxesStyle->{{Black,Thick},{Black,Thick}}]

Fourier Coefficients and Construction of Solution

Integrate[f[x]*Sin[n*π*x/L],{x,0,L}]

b[n_]:=2/L*((3 π (-60 n π (1+Cos[30] Cos[n π])+(-900-(-1+(n^2)) (π^2)) Sin[30] Sin[n π]))/(810000-1800 (1+(n^2)) (π^2)+(((-1+(n^2)))^2) (π^4)))

u[x_,t_,M_]:=Sum[b[n]*Cos[n*π*t/L]*Sin[n*π*x/L],{n,1,M}]

Testing Initial Conditions

Plot[{f[x],u[x,0,12]},{x,0,L},PlotStyle->Thickness[.01],PlotRange->{{0,L},{-1,1}},PlotStyle->Thickness[.01],AxesLabel->{"x","f(x)"},LabelStyle->Directive[Bold,Black, Large],AxesStyle->{{Black,Thick},{Black,Thick}}]

Contour Plot of Solution

ContourPlot[u[x,t,10], {x, 0, L}, {t, 0, 3*L}, PlotRange->{-1,1}, PlotLegends->Automatic, FrameLabel->{"x","t"}, LabelStyle->Directive[Bold, Black, Medium],ColorFunction->"Rainbow",ImageSize->400]

Movie of Simulation

Animate[Plot[u[x,t,12],{x,0,L},PlotStyle->Thickness[.01],PlotRange->{{0,L},{-1,1}},PlotStyle->Thickness[.01],AxesLabel->{"x","f(x)"},LabelStyle->Directive[Bold,Black, Large],AxesStyle->{{Black,Thick},{Black,Thick}}],{t,0,2*L}]