www.gusucode.com > pde 案例源码 matlab代码程序 > pde/HyperbolicEquationExample.m

    %% Hyperbolic Equation
% Solve the wave equation
%
% $$\frac{\partial^2 u}{\partial t^2} = \Delta u$$
%
% on the square domain specified by |squareg|.
%%
% Create a PDE model and import the geometry.
model = createpde;
geometryFromEdges(model,@squareg);
pdegplot(model,'EdgeLabels','on')
ylim([-1.1,1.1])
axis equal
%%
% Set Dirichlet boundary conditions $u = 0$ for $x = \pm 1$, and Neumann
% boundary conditions
%
% $$\nabla u\cdot\bf{n} = 0$$
%
% for $y = \pm 1$. (The Neumann boundary condition is the default
% condition, so the second specification is redundant.)

applyBoundaryCondition(model,'dirichlet','Edge',[2,4],'u',0);
applyBoundaryCondition(model,'neumann','Edge',[1,3],'g',0);
%%
% Set the initial conditions
u0 = 'atan(cos(pi/2*x))';
ut0 = '3*sin(pi*x).*exp(cos(pi*y))';
%%
% Set the solution times.
tlist = linspace(0,5,31);
%%
% Give coefficients for the problem.
c = 1;
a = 0;
f = 0;
d = 1;
%%
% Generate a mesh and solve the PDE.
generateMesh(model,'Hmax',0.1);
u1 = hyperbolic(u0,ut0,tlist,model,c,a,f,d);
%%
% Plot the solution at the first and last times.
figure
pdeplot(model,'XYData',u1(:,1))
figure
pdeplot(model,'XYData',u1(:,end))
%%
% For a version of this example with animation, run |pdedemo6|.