1、域对于这个示例,NUMGRID数字点在L形域内。SPY函数是一个霹葺檠溥非常有用的工具,它可以直观地显示给定矩阵中非零元素的模式。R 租涫疼迟= 'L'; % Other possible shapes include S,N,C,D,A,H,B% Generate and display the grid.n = 32;G = numgrid(R,n);spy(G)title('A finite difference grid')% Show a smaller version as sample.g = numgrid(R,12)
2、按“Enter”键。得图1、图2所示。
3、离散拉普拉斯式利用DELSQ生成离散的拉普拉斯函数。SPY函数给出了矩阵总体的图形感觉。D = delsq(G);spy(D)title('The 5-point Laplacian')% Number of interior pointsN = sum(G(:)>0)
4、按“Enter”键。得图3所示。
5、Dirichlet边值问题最后,我们解决了稀疏线性系统的Dirichlet边值问题。问题如下:delsq(u) = 1 in the interior, u = 0 on the boundary.
6、rhs = ones(N,1);if 猾诮沓靥(R == 'N') % For nested dissection, turn off minimum degree or颊俄岿髭dering. spparms('autommd',0) u = D\rhs; spparms('autommd',1)else u = D\rhs; % This is used for R=='L' as in this exampleend
7、解决方案将解决方案映射到网格中,并将其显示为等高线图。U = G;U(G>0) = full(u(G(G>0)));clabel(contour(U));prismaxis square ij
8、按“Enter”键。得如图4所示。
9、现在显示作为网格图的解决方案。colormap((cool+1)/2);mesh(U)axis([0 n 0 n 0 max(max(U))])axis square ij
10、按“Enter”键。得如图5所示。