wave equation, nonzero initial velocity

The wave equation is  (a^2) (Subscript[y, x x]) = (Subscript[y, t t])   for 0 < x < L, t > 0   
with boundary conditions 
y(0, t) = y(L, t) = 0 for t > 0 and
y(x, 0) =0,  (Subscript[y, t])(x,0) = g(x) for  0 < x < L.

This represents the vertical displacement y along the length of a tight string of length L fixed at both ends for changing time.  It has an initial nonzero velocity g.  Time begins as it is temporarily passes through the rest position so its initial displacement is 0.

Generally, we first investigate the problem with boundary conditions y(x, 0) =f(x),  (Subscript[y, t])(x,0) = 0 for  0 < x < L, which is dealt with elsewhere.


notebook created by T. Shelton, Southwestern University
reference  Elementary Differential Equations and Boundary Value Problems, Boyce & DiPrima, 8th Edition, John Wiley & Sons, Inc.; 2005. 
reference  Differential Equations: Theory, Technique, and Practice, Simmons & Krantz, McGraw-Hill Co, Inc. 2007

Set-up

You may set the parameter a  for the wave equation and the length of the string, L.

Clear[a, L];
a=2;
L = 30;

Initial velocity of the string, g(x)

You may change the function definition g .

Clear[g];
g[x_] := Piecewise[{{(2/L)x , 0 <= x < L/2.},{ (2/L)(L-x), L/2. <= x ≤L}}]

Plot[g[x],{x,0,L}, 
PlotStyle->{Green,Thickness[0.01]},AxesLabel->{" x ", "g[x] "}, PlotLabel->"GRAPH 1: Initial Velocity"]

Fit Fourier Series to g

i.e. the partial sum for the Fourier cosine series of g(x) = (Subscript[y, t])(x, t=0)

You may change the number of terms to be calculated in any series and the number of periods to plot.

Clear[ numTerms,numPeriods];
numTerms = 10;
numPeriods = 3;

Use these automatic calculations or define your own.

Clear[minX, maxX, tMax,tInc];
maxX = numPeriods * 2*L; 
minX = - (numPeriods-1) *2* L;
tMax = numPeriods*L/a;
tInc = tMax/20.;

Fourier approximation to the initial velocity of the string

Clear[c];
Table[c[n]=(2/L) NIntegrate[g[x]Sin[n π x/L],{x,0.,L}],{n,1,numTerms}];

Clear[gPartialSum,t,n]
Print["A partial sum for the Fourier sine series"]
gPartialSum[x_]=  Sum[c[n] Sin[n π x/L],{n,1,numTerms}]
Plot[{gPartialSum[x],g[x]},{x,0,L},PlotStyle->{{Blue,Dashed},{Green}},AxesLabel->{" x "},
 PlotLabel->"GRAPH 2: g is green; partial Fourier is blue and dashed"]

approximate solution to the wave equation

The solution is a function whose space domain is -∞ < x < ∞, well beyond the interval 0 < x < L on which the string physically exists.  We see that the original displacement described by f(x) on [0, L] matches the solution y(x, t=0).

Clear[y];
Print["Some terms in the wave eqn solution y[x,t]"]
y[x_,t_] = Sum[((L )/(n π a)) c[n] Sin[n π x/L] Sin[n π a t /L],{n,1,numTerms}]


Clear[VelocityInit];
Print["time derivative of the approximation to the wave eqn solution..."]
(∂_t) y[x,t]
Print["... and its value at t=0"]
VelocityInit[x_] =((∂_t) y[x,t])/.{t->0}

Show[Plot[VelocityInit[x],{x,minX,maxX},PlotStyle->{Blue,Dashed},AxesLabel->{" x "}, PlotLabel->"GRAPH 3: g green; initial velocity approx blue"],
Plot[g[x],{x,0,L},PlotStyle->{Green,Thickness[0.01]}]]

some graphs of the solution

3D graph

The solution is a two dimensional surface, plotted in GRAPH 6, because the string displacement changes both along the string and in time.  Here we show it for the physical string (0 < x < L) and a time interval. 
Each frame in GRAPH 5 is a slice of this surface for a particular t.
Each frame in GRAPH 6 is a slice of this surface through the x-value.

Plot3D[y[x,t],{x,0, L}, {t, 0,tMax},AxesLabel->{"x","t","y"}, 
PlotLabel->"GRAPH 4: y[x,t]"]

additional graph settings

You may change 
the max and min values for the vertical displacement of the string for subsequent graphs. 

These values should be a bit beyond the vertical values on the 3D graph

Clear[minY, maxY];
minY= -4.;
 maxY = 4.;

interesting slices of the 3D graph

Each image is a view of the string frozen in time.  See how the wave equation solution along the length of the string changes over  time by sliding the value of time. The boundary conditions guarantee that the ends always stay on the x-axis.

Manipulate[
Plot[y[x,t],{x,0, L}, PlotRange->{minY,maxY},AxesLabel->{" x "}, 
PlotLabel->"GRAPH 5: time-slice of wave eqn approx along the string"],
{{t,tInc,"t"},0,tMax,tInc}]

Each image focuses on a single point on the string, showing how that point on the string changes in time.  Slide the space variable x to see the time changes for other points on the string.

Manipulate[
Plot[y[x,t],{t,0,tMax}, PlotRange->{minY,maxY},AxesLabel->{" t "}, 
PlotLabel->"GRAPH 6: space-slice of wave eqn approx in time"],
{{x,0.5,"x"},0,L,.05}]

extended solution to the wave equation

The solution actually exists on a "virtual string" that is infinite in both directions, as we saw in GRAPH 3 above.  For each position along the virtual string, see how that point changes in time.  Slide along for different points in the extended space variable.

Manipulate[
Plot[y[x,t],{t,0,tMax}, PlotRange->{minY,maxY},AxesLabel->{" t "}, 
PlotLabel->"GRAPH 7: space-slice of wave eqn approx in time; virtual string"],
{{x,minX,"x"},minX,maxX,.05}]

Plot3D[y[x,t],{x,minX, maxX},  {t, 0,tMax},AxesLabel->{"x","t","y"},PlotLabel->"GRAPH 8: y[x,t] for a virtual string"]