www.gusucode.com > pde 案例源码 matlab代码程序 > pde/EigenvaluesOfASquareUsingCommandLineFunctionsExample.m
%% Eigenvalues of a Square Using Command-Line Functions % This example shows how to compute the eigenvalues and eigenmodes of a % square domain using command-line functions. The geometry description file % file for this problem is called |squareg.m|. % % Create a model and import the geometry. model = createpde(); geometryFromEdges(model,@squareg); %% % Set zero Neumann boundary conditions on all edges. applyBoundaryCondition(model,'neumann','Edge',1:model.Geometry.NumEdges,'g',0); %% % The eigenvalue PDE coefficients for this problem are _c_ = 1, _a_ = 0, % and _d_ = 1. You can enter the eigenvalue range |r| as the vector |[-Inf % 10]|. specifyCoefficients(model,'m',0,'d',1,'c',1,'a',0,'f',0); r = [-Inf,10]; %% % Create a mesh and solve the problem. generateMesh(model,'Hmax',0.05); results = solvepdeeig(model,r); %% % Plot the fourth eigenfunction as a surface plot. u = results.Eigenvectors; pdeplot(model,'XYData',u(:,4),'ZData',u(:,4)); %% % This problem is _separable_, meaning % % $$u(x,y) = f(x)g(y).$$ % % The functions _f_ and _g_ are eigenfunctions in the _x_ and _y_ % directions, respectively. In the _x_ direction, the first eigenmode is a % slowly increasing exponential function. The higher modes include % sinusoids. In the _y_ direction, the first eigenmode is a straight line % (constant), the second is half a cosine, the third is a full cosine, the % fourth is one and a half full cosines, etc. These eigenmodes in the _y_ % direction are associated with the eigenvalues % % $$ 0, \frac{\pi^2}{4}, \frac{4\pi^2}{4}, \frac{9\pi^2}{4},...$$ % % There are five eigenvalues smaller than 10 for this problem, and the % first one is even negative (-0.4145). It is possible to trace the % preceding eigenvalues in the eigenvalues of the solution. Looking at a % plot of the first eigenmode, you can see that it is made up of the first % eigenmodes in the _x_ and _y_ directions. The second eigenmode is made up % of the first eigenmode in the _x_ direction and the second eigenmode in % the _y_ direction. % % Look at the difference between the first and the second eigenvalue % compared to $\pi^2/4$: l = results.Eigenvalues; l(2)-l(1) %% % pi^2/4 %% % Likewise, the fifth eigenmode is made up of the first eigenmode in the % _x_ direction and the third eigenmode in the _y_ direction. As expected, % |l(5)-l(1)| is approximately equal to $\pi^2$: l(5) - l(1) - pi^2 %% % You can explore higher modes by increasing the search range to include % eigenvalues greater than 10.