function [Q]= qdecmpc(A,B) % % Author: Nasser M. Abbasi, Northeastern University % % functionality: % -1 % contruct the P , or Q , a constant nonsingular matrix which % transforms a noncontrollable state equation into a controllable % one. % The algorithm used is that of lemma 3.5 , page 74 of book % computer aided analysis and design of Linear control systems % by Jamshidi,Tarokh,Shafai % % arguments: % A: IN, the A matrix of the state equation % B: IN, the B matrix of the state equation % Q: OUT, the Q transformation matrix % if(nargin ~= 2) error('Number of input arguments must be 2, A,B matrices'); end [row,col]= size(A); if(row ~= col) error('Matrix A supplied is not a SQUARE matrix'); end % % first find the controllabilty matrix % rc= ltirc(A,B); [original_row,original_col]= size(rc); % % t is the temp matrix we use to build Q from % t(1:original_row,1) = rc(1:original_row,1); old_rc_col= 2; new_rc_col= 1; % % Now loop over all columns of Rc, select those that are % Linearly independent with each others, ignore the rest % for i=2:original_col temp= t; temp(1:original_row,new_rc_col+1)= rc(1:original_row,i); [row,col]= size(orth(temp)); if (col==new_rc_col+1) t=temp; new_rc_col= new_rc_col+1; end end % % now see if the matrix t build has rank same as A % if not, we need to come up with arbitrary columns % that are linearly independent with those allready % extracted from Rc from above % [arow,acol]= size(A); [row,col]= size(t); if(col == acol) Q=t; else dif= acol-col; for i=1:dif temp=t; more=1; while (more==1) % % The trick i use to find arbitrary column that is L.I. with % those allready in Q, is by random generation, using the % built in magic function, I keep looping, generating random % columns untill i find one that is L.I., then i use it % temp1= magic(original_row); temp(1:original_row,new_rc_col+i)= temp1(1:original_row,1:1); [row,col]= size(orth(temp)); if(col == new_rc_col+i) more=0; t=temp; end end end Q=t; end