号令行窗口键入:
% Define the variables.
[B,V] = bucky;
H = sparse(60,60);
k = 31:60;
H(k,k) = B(k,k);
% Visualize the variables.
gplot(B-H,V,'b-');
hold on
gplot(H,V,'r-');
hold off
axis off equal
按”Enter“键。
如图1所示。
一个图可以用它的邻接矩阵来暗示。
为了机关邻接矩阵,将节点编号为1到N。
若是节点i毗连到节点j,则将矩阵的元素(i,j)设置为1,不然设置为0。
号令行窗口键入:
% Define a matrix A.
A = [0 1 1 0 ; 1 0 0 1 ; 1 0 0 1 ; 0 1 1 0];
% Draw a picture showing the connected nodes.
cla
subplot(1,2,1);
gplot(A,[0 1;1 1;0 0;1 0],'.-');
text([-0.2, 1.2 -0.2, 1.2],[1.2, 1.2, -.2, -.2],('1234')', ...
'HorizontalAlignment','center')
axis([-1 2 -1 2],'off')
% Draw a picture showing the adjacency matrix.
subplot(1,2,2);
xtemp = repmat(1:4,1,4);
ytemp = reshape(repmat(1:4,4,1),16,1)';
text(xtemp-.5,ytemp-.5,char('0'+A(:)),'HorizontalAlignment','center');
line([.25 0 0 .25 NaN 3.75 4 4 3.75],[0 0 4 4 NaN 0 0 4 4])
axis off tight
按”Enter“键。
如图2所示。
这里的节点在一个半球的巴克球,编号多边形的多边形。
号令行窗口键入:
subplot(1,1,1);
gplot(B(1:30,1:30),V(1:30,:),'b-');
for j = 1:30,
text(V(j,1),V(j,2),int2str(j),'FontSize',10);
end
axis off equal
按”Enter“键。
如图3所示。
为了可视化这个半球的邻接矩阵,我们利用SPY函数来绘制非零元素的轮廓。
注重,矩阵是对称的,因为若是节点i毗连到节点j,那么节点j毗连到节点i。
号令行窗口键入:
spy(B(1:30,1:30))
title('spy(B(1:30,1:30))')
按”Enter“键。
如图4所示。
此刻我们经由过程将一个半球的编号映射到另一个半球,将我们的编号方案扩展到整个图形。
号令行键入:
[B,V] = bucky;
H = sparse(60,60);
k = 31:60;
H(k,k) = B(k,k);
gplot(B-H,V,'b-');
hold on
gplot(H,V,'r-');
for j = 31:60
text(V(j,1),V(j,2),int2str(j), ...
'FontSize',10,'HorizontalAlignment','center');
end
hold off
axis off equal
按”Enter“键。
如图5所示。
最后,这里是最终稀少矩阵的间谍图。
号令行键入:
spy(B)
title('spy(B)')
按”Enter“键。
如图6所示。
在很多有效的图中,每个节点只毗连到少数其他节点。
是以,邻接矩阵每行只包含几个非零项。
这个例子展示了一个稀少矩阵有效的处所。
号令行窗口键入:
gplot(B-H,V,'b-');
axis off equal
hold on
gplot(H,V,'r-');
hold off
按”Enter“键。
如图7所示。
0 篇文章
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!