This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Wave Equation

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


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,




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 Modeler App

Use the PDE Modeler 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


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:


and for ∂u/∂t , enter


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


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();

View the geometry

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.


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));

Create the model coefficients. The equation is

where , , and .

m = 1;
c = 1;
f = 0;

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.

results = solvepde(model,tlist);

Animate the solution.

u = results.NodalSolution;

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

M = moviein(n);
for i=1:n,
    axis([-1 1 -1 1 umin umax]);
    caxis([umin umax]);
    M(:,i) = getframe;

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

Was this topic helpful?