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

$$\frac{{\partial}^{2}u}{\partial {t}^{2}}-\Delta 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*(*t*_{0})
and ∂*u*(*t*_{0})/∂*t*

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

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

and

$${\frac{\partial u\left(x,y,t\right)}{\partial t}|}_{t=0}=3\mathrm{sin}\left(\pi x\right)\mathrm{exp}\left(\mathrm{sin}\left(\frac{\pi}{2}y\right)\right)$$

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

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

$$d\frac{{\partial}^{2}u}{\partial {t}^{2}}-\nabla \cdot \left(c\nabla u\right)+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.

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
at the top and bottom. The initial conditions are

and

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,'dirichlet','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

where , , and .

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?