Wave Equation with a Source

Problem from Class

In this section we want to solve the following heat equation with a spatial source term:
u_tt=u_xx+sin(2x)*sin(2t)
u(0,t)=0
u(π,t)=0
u(x,0)=0
u_t(x,0)=0

Auxiliary Solution

From class we know that:

w[x_,t_,τ_]:=Sin[2*τ]/2*Sin[2*t]*Sin[2*x];

Full Solution

To determine the actual solution we integrate

Integrate[w[x,t-τ,τ],{τ,0,t}]

u[x_,t_]:=(1/8) (-2 t Cos[2 t]+Sin[2 t]) Sin[2 x]

Plot of Full Solution

T=10;
DensityPlot[u[x,t], {x, 0, π}, {t, 0, T}, PlotRange->All, PlotLegends->Automatic, PlotPoints-> 30, FrameLabel->{"x","t"}, LabelStyle->Directive[Bold, Black, Medium],ColorFunction->"Rainbow"]

ContourPlot[u[x,t], {x, 0, π}, {t, 0, T}, PlotRange->All, PlotLegends->Automatic, PlotPoints-> 30, FrameLabel->{"x","t"}, LabelStyle->Directive[Bold, Black, Medium],ColorFunction->"Rainbow",Contours->20]

Plot of Full Solution

Animate[Plot[u[x,t],{x,0,π},PlotRange->{-2.5,2.5},PlotStyle->Thickness[.01],PlotRange->All,AxesLabel->{"x","u(x,t)"},LabelStyle->Directive[Bold, Black,Medium],AxesStyle->Directive[Black, 12]],{t,0,10}]

Slightly Different Solution

In this section we want to solve the following heat equation with a spatial source term:
u_tt=u_xx+sin(2x)*sin(3t)
u(0,t)=0
u(π,t)=0
u(x,0)=0
u_t(x,0)=0

Auxiliary Solution

We can determine that

w[x_,t_,τ_]:=Sin[3*τ]/2*Sin[2*t]*Sin[2*x];

Full Solution

To determine the actual solution we integrate

Integrate[w[x,t-τ,τ],{τ,0,t}]

u[x_,t_]:=(1/10) (3 Sin[2 t]-2 Sin[3 t]) Sin[2 x]

Plot of Full Solution

T=10;
DensityPlot[u[x,t], {x, 0, π}, {t, 0, T}, PlotRange->All, PlotLegends->Automatic, PlotPoints-> 30, FrameLabel->{"x","t"}, LabelStyle->Directive[Bold, Black, Medium],ColorFunction->"Rainbow"]

ContourPlot[u[x,t], {x, 0, π}, {t, 0, T}, PlotRange->All, PlotLegends->Automatic, PlotPoints-> 30, FrameLabel->{"x","t"}, LabelStyle->Directive[Bold, Black, Medium],ColorFunction->"Rainbow",Contours->20]

Plot of Full Solution

Animate[Plot[u[x,t],{x,0,π},PlotRange->{-1,1},PlotStyle->Thickness[.01],PlotRange->All,AxesLabel->{"x","u(x,t)"},LabelStyle->Directive[Bold, Black,Medium],AxesStyle->Directive[Black, 12]],{t,0,15}]