function G = ifdiag(G) % IFDIAG Algorithm in section 5.2 % G = IFDIAG(G) performs one step of the algorithm in % section 5.2 to transform the upper m-by-n part of G to % a strongly diagonal matrix. G must be in hat format. % % An m-by-n matrix is strongly diagonal if it is diagonal % and if, in addition, (1) each diagonal entry after the % first is an integer multiple of the preceding diagonal % entry, and (2) there are no negative entries, except that % in a square matrix the last diagonal entry may be negative. % % See also QUICKE % Adapted from Harold M. Edwards, "Linear Algebra." % Written by Serge Tchikanda 06/24/95. % Last revised by Serge Tchikanda 06/28/96. A = unhat(G); [m,n,OPERATIONS] = priority(A); if ~isempty(m) | ~isempty(n) % if matrix is not diagonal disp(' ') disp(' Upper m-by-n matrix must be diagonal.') return end [mrows,ncols] = size(A); for i=2:min(size(A)) if A(i-1,i-1) ~= 0 if rem(A(i,i),A(i-1,i-1))~=0 G(i-1,:) = G(i-1,:) + G(i,:); return end elseif A(i-1,i-1) == 0 & A(i,i) ~= 0 G(i-1,:) = G(i-1,:) + G(i,:); return end end for i=1:min(size(A)) if A(i,i) < 0 if i ~= ncols G(:,i+1) = G(:,i+1) - G(:,i); return elseif i ~= mrows G(i+1,:) = G(i+1,:) - G(i,:); return end end end disp(' ') disp(' Matrix is strongly diagonal.')