Galerkin Methods

Nonlinear wave equation

Take, as our basis, the sine functions for x in [0,1]:

Phi[j_, x_] := Sqrt[2] Sin[Pi j x]

We’ll generate the expressions for the ODE solver symbolically.  For (Subscript[u, 5])we have five terms in the ansatz, and we run that through the nonlinear wave equation version of interest to us, (15.23), giving residual (Subscript[r, 5]):

Nn = 5;
uN = Sum[ToExpression["a"<>ToString[j]<>"[t]"] Phi[j,x],{j,1,Nn}];
rn = us D[D[uN,t],t] - T0 D[D[uN,x],x] - (3/2) K D[uN,x]^2 D[D[uN,x],x];

Now integrate the residual times the Phi[k,x] for k = 1 -> 5, as in (15.38).  We’ll set the resulting ODEs to zero, requiring that any error live in the space spanned by Phi[k,x] for k = 6 -> ∞:

req = Table[Integrate[Expand[rn Phi[j,x]],{x,0,1}],{j,1,Nn}];

Below, we’ll use the built-in differential equation solver, NDSolve, to generate solutions for the time-dependent coefficients in the decomposition - initially, the string is at rest, in Phi[1,x]:

us = 1.0;
K = 1.0;
T0 = K .5;
nrep = NDSolve[{req[[1]] == 0, req[[2]] == 0, req[[3]] ==0 ,req[[4]] ==0,req[[5]]==0,a1[0] ==1, a1'[0] == 0,a2[0] == 0, a2'[0] == 0, a3[0] == 0, a3'[0] == 0, a4[0] == 0, a4'[0] == 0, a5[0] == 0, a5'[0] == 0},{a1[t],a2[t],a3[t],a4[t],a5[t]},{t,0,1}]

Here’s a plot of the odd coefficients, this is Figure 15.2,

GraphicsGrid[{{Plot[a1[t]/. nrep,{t,0,1},PlotStyle->GrayLevel[0.5]]},{Plot[a3[t]/. nrep,{t,0,1},PlotStyle->GrayLevel[0.5]]},{Plot[a5[t]/. nrep,{t,0,1},PlotStyle->GrayLevel[0.5]]}}]

We can make a movie of the motion by combining the time-dependent coefficients with their basis functions, forming the full (Subscript[u, 5]):

mov = Table[Plot[uN/. nrep /. t-> T,{x,0,1},PlotRange->{-2,2},PlotStyle->GrayLevel[0.5]],{T,0,.4,.01}];

ListAnimate[mov]

and a few snapshots from the movie give Figure 15.3:

GraphicsGrid[{{mov[[1]], mov[[8]]},{mov[[16]],mov[[24]]},{mov[[32]],mov[[40]]}}]