Solve an Initial Value Problem for the Wave Equation
Specify the wave equation with unit speed of propagation.
In[1]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_1.png)
weqn = D[u[x, t], {t, 2}] == D[u[x, t], {x, 2}];
Prescribe initial conditions for the equation.
In[2]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_2.png)
ic = {u[x, 0] == E^(-x^2), Derivative[0, 1][u][x, 0] == 1};
Solve the initial value problem.
In[3]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_3.png)
DSolveValue[{weqn, ic}, u[x, t], {x, t}]
Out[3]=
![](assets.en/solve-an-initial-value-problem-for-the-wave-equati/O_1.png)
The wave propagates along a pair of characteristic directions.
In[4]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_4.png)
DSolveValue[{weqn, ic}, u[x, t], {x, t}];
Plot3D[%, {x, -7, 7}, {t, 0, 4}, Mesh -> None]
Out[4]=
![](assets.en/solve-an-initial-value-problem-for-the-wave-equati/O_2.png)
Solve the initial value problem with piecewise data.
In[5]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_5.png)
ic = {u[x, 0] == UnitBox[x] + UnitTriangle[x/3],
Derivative[0, 1][u][x, 0] == 0};
In[6]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_6.png)
DSolveValue[ {weqn, ic}, u[x, t], {x, t}]
Out[6]=
![](assets.en/solve-an-initial-value-problem-for-the-wave-equati/O_3.png)
Discontinuities in the initial data are propagated along the characteristic directions.
In[7]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_7.png)
DSolveValue[ {weqn, ic}, u[x, t], {x, t}];
Plot3D[%, {x, -7, 7}, {t, 0, 4}, PlotRange -> All, Mesh -> None,
ExclusionsStyle -> Red]
Out[7]=
![](assets.en/solve-an-initial-value-problem-for-the-wave-equati/O_4.png)
Solve the initial value problem with a sum of exponential functions as initial data.
In[8]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_8.png)
ic = {u[x, 0] == E^(-(x - 6)^2) + E^(-(x + 6)^2),
Derivative[0, 1][u][x, 0] == 1/2};
In[9]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_9.png)
sol = DSolveValue[ {weqn, ic}, u[x, t], {x, t}]
Out[9]=
![](assets.en/solve-an-initial-value-problem-for-the-wave-equati/O_5.png)
Visualize the solution.
In[10]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-wave-equati/In_10.png)
Plot3D[sol, {x, -30, 30}, {t, 0, 20}, PlotRange -> All, Mesh -> None,
PlotPoints -> 30]
Out[10]=
![](assets.en/solve-an-initial-value-problem-for-the-wave-equati/O_6.png)