Documentation

Wave Equation

As an example of a hyperbolic PDE, let us solve the wave equation

2ut2Δu=0

for transverse vibrations of a membrane on a square with corners in (–1,–1), (–1,1), (1,–1), and (1,1). The membrane is fixed (u = 0) at the left and right sides, and is free (∂u/∂n = 0) at the upper and lower sides. Additionally, we need initial values for u(t0) and ∂u(t0)/∂t

The initial values need to match the boundary conditions for the solution to be well-behaved. If we start at t = 0,

u(x,y,0)=arctan(cos(π2x))

and

u(x,y,t)t|t=0=3sin(πx)exp(sin(π2y))

are initial values that satisfy the boundary conditions. The reason for the arctan and exponential functions is to introduce more modes into the solution.

Using the PDE App

Use the PDE app in the generic scalar mode. Draw the square using the Rectangle/square option from the Draw menu or the button with the rectangle icon. Proceed to define the boundary conditions by clicking the ∂Ω button and then double-click the boundaries to define the boundary conditions.

Initialize the mesh by clicking the Δ button or by selecting Initialize mesh from the Mesh menu.

Also, define the hyperbolic PDE by opening the PDE Specification dialog box, selecting the hyperbolic PDE, and entering the appropriate coefficient values. The general hyperbolic PDE is described by

d2ut2(cu)+au=f,

so for the wave equation you get c = 1, a = 0, f = 0, and d = 1.

Before solving the PDE, select Parameters from the Solve menu to open the Solve Parameters dialog box. As a list of times, enter linspace(0,5,31) and as initial values for u:

atan(cos(pi/2*x)) 

and for ∂u/∂t , enter

3*sin(pi*x).*exp(sin(pi/2*y))

Finally, click the = button to compute the solution. The best plot for viewing the waves moving in the x and y directions is an animation of the whole sequence of solutions. Animation is a very memory-consuming feature, so you may have to cut down on the number of times you compute a solution. A good suggestion is to check the Plot in x-y grid option. Using an x-y grid can speed up the animation process significantly.

Wave Equation Using Command-Line Functions

This example shows how to solve the wave equation using command-line functions. It solves the equation with boundary conditions u = 0 at the left and right sides, and $\partial u/\partial n = 0$ at the top and bottom. The initial conditions are

$$ u(x,y,0) = \arctan\left (\cos\left (\frac{\pi}{2} x\right )\right )$$

and

$$\frac{\partial u}{\partial t} = 3\sin(\pi x)\exp\left (\sin\left
(\frac\pi 2 y\right )\right ) \hbox{ at }t = 0.$$

Calculate the solution every 0.05 seconds for five seconds.

The geometry is described in the file squareg.m.

First, create the geometry.

model = createpde();
geometryFromEdges(model,@squareg);

View the geometry

pdegplot(model,'EdgeLabels','on');
ylim([-1.1,1.1])
axis equal

Set the boundary conditions to u = 0 on the left and right boundaries (edges 2 and 4). The default boundary conditions are appropriate for edges 1 and 3, so you do not need to set them.

applyBoundaryCondition(model,'Edge',[2,4],'u',0);

Set the initial conditions.

u0 = @(locations)atan(cos(pi/2*locations.x));
ut0 = @(locations)3*sin(pi*locations.x).*exp(sin(pi/2*locations.y));
setInitialConditions(model,u0,ut0);

Create the model coefficients. The equation is

$$m\frac{\partial^2 u}{\partial t^2}-\nabla\cdot(c\nabla u) = f,$$

where $m = 1$, $c = 1$, and $f = 0$.

m = 1;
c = 1;
f = 0;
specifyCoefficients(model,'m',m,'d',0,'c',c,'a',0,'f',f);

Set the solution times.

n = 31; % number of frames in eventual animation
tlist = linspace(0,5,n); % list of times

You are now ready to solve the wave equation. Create a mesh and call the solver.

generateMesh(model);
results = solvepde(model,tlist);

Animate the solution.

u = results.NodalSolution;

umax = max(max(u));
umin = min(min(u));

figure;
M = moviein(n);
for i=1:n,
    pdeplot(model,'xydata',u(:,i),'zdata',u(:,i),...
    'xygrid','on','colorbar','off');
    axis([-1 1 -1 1 umin umax]);
    caxis([umin umax]);
    M(:,i) = getframe;
end

You can review the movie by executing movie(M,10). There is a complete solution of this problem, including animation, in pdedemo6. If you have lots of memory, you can try increasing n, the number of frames in the movie.

Was this topic helpful?