www.gusucode.com > pde 案例源码 matlab代码程序 > pde/HyperbolicEquationWithDampingExample.m
%% Hyperbolic Equation with Damping % Solve a hyperbolic problem that includes damping. You must use the finite % element matrix form to use damping. %% % Create a model and import the |BracketWithHole.stl| geometry. model = createpde(); importGeometry(model,'BracketWithHole.stl'); figure pdegplot(model,'FaceLabels','on') view(30,30) title('Bracket with Face Labels') figure pdegplot(model,'FaceLabels','on') view(-134,-32) title('Bracket with Face Labels, Rear View') %% % Set coefficients |c = 1|, |a = 0|, |f = 0.5|, and |d = 1|. c = 1; a = 0; f = 0.5; d = 1; %% % Generate a mesh for the model. generateMesh(model); %% % Create initial conditions and boundary conditions. The boundary condition % for the rear face is Dirichlet with value 0. All other faces have the % default boundary condition. The initial condition is |u(0) = 0|, % |du/dt(0) = x/2|. Give the initial condition on the derivative by % calculating the |x|-position of each node in |xpts|, and passing |x/2|. applyBoundaryCondition(model,'Face',4,'u',0); u0 = 0; xpts = model.Mesh.Nodes(1,:); ut0 = xpts(:)/2; %% % Create the associated finite element matrices. [Kc,Fc,B,ud] = assempde(model,c,a,f); [~,M,~] = assema(model,0,d,f); %% % Use a damping matrix that is 10% of the mass matrix. Damping = 0.1*M; %% % Solve the PDE for times from 0 to 2. tlist = linspace(0,5,50); u = hyperbolic(u0,ut0,tlist,Kc,Fc,B,ud,M,'DampingMatrix',Damping); %% % Plot the maximum value at each time. The oscillations damp slightly as % time increases. plot(max(u)) xlabel('Time') ylabel('Maximum value') title('Maximum of Solution')