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

    %% Parabolic Equation Using Legacy Syntax
% Solve the parabolic equation
%
% $$\frac{\partial u}{\partial t} = \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$ on all edges. The |squareb1|
% function specifies these boundary conditions.
b = @squareb1;
%%
% Generate a relatively fine mesh.
[p,e,t] = initmesh(g,'Hmax',0.02);
%%
% Set the initial condition to have $u(0) = 1$ on the disk $x^2 + y^2 \le
% 0.4^2$ and $u(0) = 0$ elsewhere.
u0 = zeros(size(p,2),1); 
ix = find(sqrt(p(1,:).^2 + p(2,:).^2) <= 0.4); 
u0(ix) = ones(size(ix));
%%
% Set solution times to be from 0 to 0.1 with step size 0.005.
tlist = linspace(0,0.1,21);
%%
% Create the PDE coefficients.
c = 1;
a = 0;
f = 0;
d = 1;
%%
% Solve the PDE.
u = parabolic(u0,tlist,b,p,e,t,c,a,f,d);
%%
% Plot the initial condition, the solution at the final time, and two
% intermediate solutions.
figure
subplot(2,2,1)
pdeplot(p,e,t,'XYData',u(:,1));
axis equal
title('t = 0')
subplot(2,2,2)
pdeplot(p,e,t,'XYData',u(:,5))
axis equal
title('t = 0.02')
subplot(2,2,3)
pdeplot(p,e,t,'XYData',u(:,11))
axis equal
title('t = 0.05')
subplot(2,2,4)
pdeplot(p,e,t,'XYData',u(:,end))
axis equal
title('t = 0.1')