號令行窗口鍵入:
% 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所示。
END0 篇文章
如果覺得我的文章對您有用,請隨意打賞。你的支持將鼓勵我繼續創作!