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

    %% Hyperbolic Equation using Legacy Syntax
% Solve the wave equation
%
% $$\frac{\partial^2 u}{\partial t^2} = \Delta u$$
%
% on the square domain specified by |squareg|, using a geometry function to
% specify the geometry, a boundary function to specify the boundary
% conditions, and using |initmesh| to create the finite element mesh.
%%
% Specify the geometry as |@squareg| and plot the geometry.
g = @squareg;
pdegplot(g,'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.)
%
% The |squareb3| function specifies these boundary conditions.
b = @squareb3;
%%
% 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;
%%
% Create a mesh and solve the PDE.
[p,e,t] = initmesh(g);
u = hyperbolic(u0,ut0,tlist,b,p,e,t,c,a,f,d);
%%
% Plot the solution at the first and last times.
figure
pdeplot(p,e,t,'XYData',u(:,1))
figure
pdeplot(p,e,t,'XYData',u(:,end))
%%
% For a version of this example with animation, run |pdedemo6|.