function T = tilt(n,rc,v); %TILT Tilt matrix. % T = TILT(n,rc,v) returns a tilt T from the % n by n identity matrix. % % RC is a constant specifying the type of transformation % to be performed on the identity matrix. % RC = 1 means that a row of the n by n identity % matrix will be added to or subtracted from another row. % RC = 2 means that a column of the n by n identity % matrix will be added to or subtracted from another column. % % V is a two-component vector containing the indices % of the two rows or columns used in the transformation. % V(1) specifies the row or column to be added to or % subtracted from the row or column specified by V(2). % In either case, the result is kept in the row or % column specified by V(2). A negative V(1) means that the % column or row specified by abs(V(1)) is to be subtracted % from the column or row specified by V(2). % % For example, T = tilt(4,1,[-3 2]) returns a tilt T in % which the third row of the 4 by 4 identity matrix is % subtracted from the second row. % % Note: V(2) should be positive. % % See also FASTTILT % For use with A Matlab Guide to Linear Algebra by Harold M. Edwards. % By Serge Tchikanda. Last revised 09/18/96. T = eye(n); % creating the n by n identity matrix if rc == 1 % checking if row operation % is to be perfomed. r1 = v(1); r2 = v(2); if r1 < 0 T(r2,:) = T(r2,:) - T(abs(r1),:); else T(r2,:) = T(r2,:) + T(abs(r1),:); end elseif rc == 2 % checking if column operation % is to be performed. c1 = v(1); c2 = v(2); if c1 < 0 T(:,c2) = T(:,c2) - T(:,abs(c1)); else T(:,c2) = T(:,c2) + T(:,abs(c1)); end else error('Unrecognizable operation') end