Wave Equation with Dirichlet Boundary Conditions and Zero Initial Velocity

Consider the Equation u_tt=c^2*u_xx on the domain [0,L] with Dirichlet boundary conditions and initial profile u(0,x)=f(x). We know that the generic form of the solution is given by
	u(t,x)=(∑_(n=1)^∞)(Subscript[b, n]) cos(((nπct)/L))sin(((nπx)/L))
We want to plot the generic behavior of such solutions for different functions.

Example

Lets consider the problem on the domain [0,2] with γ=3 and initial profile f(x)=x(1-x)(2-x).

L=2;
c=3;
f[x_]:=x*(1-x)(2-x);

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

b[n_]:=((8 (-1+(((-1))^n)) (-12+(n^2) (π^2)))/((n^4) (π^4)))
u[t_,x_,N_]:=Sum[b[n]*Cos[n*π*c*t/L]*Sin[n*π*x/L],{n,1,N}];

Plot[{u[0,x,30],u[.4,x,20],u[.8,x,20],u[1.2,x,20],u[1.6,x,20],u[2,x,20]},{x,0,L},PlotStyle->Thick,AxesStyle->Directive[Black, 12],AxesLabel->{"x","u(t,x)"}]

ContourPlot[u[t,x,20],{t,0,3},{x,0,2},PlotRange->{-1/2,1/2},FrameStyle->Directive[Black, 12],FrameLabel->{"t","x"},PlotPoints->30]

Wave Equation with Dirichlet Boundary Conditions and Initial Velocity

Consider the Equation u_tt=c^2u_xx on the domain [0,L] with Dirichlet boundary conditions and initial velocity profile u_t(0,x)=f(x). We know that the generic form of the solution is given by
	u(t,x)=(∑_(n=1)^∞)(Subscript[b, n]) sin(((nπct)/L))cos(((nπx)/L))
We want to plot the generic behavior of such solutions for different functions.

Example

Lets consider the problem on the domain [0,2] with c=3 and initial velocity f(x)=x*(1-x)*(2-x).

L=2;
c=3;
f[x_]:=x*(1-x)*(2-x);

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

b[n_]:=((16 (1+(((-1))^n)))/((n^4) (π^4)));
u[t_,x_,N_]:=Sum[b[n]*Sin[n*π*c*t/L]*Sin[n*π*x/L],{n,1,N}];

Plot[{u[0,x,20],u[.2,x,40],u[.4,x,40],u[.6,x,20],u[.8,x,40],u[1,x,40]},{x,0,L},PlotRange->{-1/10,1/10},PlotStyle->Thick,AxesStyle->Directive[Black, 12],AxesLabel->{"x","u(t,x)"}]

ContourPlot[u[t,x,20],{t,0,2},{x,0,2},PlotRange->{-1/10,1/10},FrameStyle->Directive[Black, 12],FrameLabel->{"t","x"},Contours->20,PlotPoints->30]