域
對于這個示例,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)
按“Enter”鍵。
得圖1、圖2所示。
離散拉普拉斯式
操縱DELSQ生當作離散的拉普拉斯函數。SPY函數給出了矩陣總體的圖形感受。
D = delsq(G);
spy(D)
title('The 5-point Laplacian')
% Number of interior points
N = sum(G(:)>0)
按“Enter”鍵。
得圖3所示。
Dirichlet邊值問題
最后,我們解決了稀少線性系統的Dirichlet邊值問題。問題如下:
delsq(u) = 1 in the interior,
u = 0 on the boundary.
rhs = ones(N,1);
if (R == 'N') % For nested dissection, turn off minimum degree ordering.
spparms('autommd',0)
u = D\rhs;
spparms('autommd',1)
else
u = D\rhs; % This is used for R=='L' as in this example
end
解決方案
將解決方案映射到網格中,并將其顯示為等高線圖。
U = G;
U(G>0) = full(u(G(G>0)));
clabel(contour(U));
prism
axis square ij
按“Enter”鍵。
得如圖4所示。
此刻顯示作為網格圖的解決方案。
colormap((cool+1)/2);
mesh(U)
axis([0 n 0 n 0 max(max(U))])
axis square ij
按“Enter”鍵。
得如圖5所示。
0 篇文章
如果覺得我的文章對您有用,請隨意打賞。你的支持將鼓勵我繼續創作!