% Lecture 36: SPECIAL MATRICES % using sparse matrices a = sparse(3,4,5,10,10); spy(a); a = sparse([3,3,3,3],[4,5,7,8],[5,4,3,2],10,10); spy(a); a(3,5); a(3,5) ans = 4 a(1,1) ans = 0 % Pascal matrix p10 = pascal(10); p10 = mod(p10,2); spy(p10); % convert to a sparse matrix s10 = sparse(p10); [i,j,v] = find(s10); % make the table of entries of s10 norm(p10-s10) ans = 0 % Triagonal marices i = [1:6 2:6 1:5]; j = [1:6 1:5 2:6]; v = [2*ones(1,6) ones(1,5) 3*ones(1,5)]; d3 = sparse(i,j,v); spy(d3); % NETWORK cd h: fschange('H:\nodes.m'); A = ones(12); [x,y]=nodes(12); hold on gplot(A,[x' y']); % the complete graph % make the adjacency matrix for network with % all odd nodes linked to #1 and all even - to #8 A = spalloc(12,12,12); for i=1:12 if mod(i,2)==0 A(i,8)=1; else A(i,1)=1; end; end; A(1,1)=0; A(8,8)=0; A = A + A'; openvar('A', A); figure [x,y]=nodes(12); gplot(A, [x' y']); [x,y]=nodes(12); hold on gplot(A, [x' y']); A(1,8)=1; A(8,1)=1; gplot(A, [x' y']); diary off