function [P]= pdecmpo(A,C) % % Author: Nasser M. Abbasi, Northeastern University % % functionality: % -1 % contruct the P , or Q , a constant nonsingular matrix which % transforms a nonobservable state equation into an observable % one and nonobservable parts. % The algorithm used is that of lemma 3.6 , 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 % C: IN, the C matrix of the state equation % P: OUT, the P transformation matrix % if(nargin ~=2) error('Number of input arguments must be 2, the A and C matrix'); end [row,col]= size(A); if(row ~= col) error('Matrix A supplied must be SQUARE matrix'); end % % first find the observability matrix % ro= ltiro(A,C); [original_row,original_col]= size(ro); % % t is the temp matrix we use to build P from % t(1,1:original_col) = ro(1,1:original_col); old_ro_row= 2; new_ro_row= 1; % % Now loop over all rows of Ro, select those that are % Linearly independent with each others, ignore the rest % for i=2:original_row temp= t; temp(new_ro_row+1,1:original_col)= ro(i,1:original_col); % % rotate by 90 the matrix, because i want to see if rows % are L.I. to each others not the columns % you have to be carfull here, make sure we check the % column number in the rot matrix with the row number of % the Ro matrix, if you draw a picture you'll see it % rot= rot90(temp); [row,col]= size(orth(rot)); if (col==new_ro_row+1) t=temp; new_ro_row= new_ro_row+1; end end % % now see if the matrix t build has rank same as A % if not, we need to come up with arbitrary rows % that are linearly independent with those allready % extracted from Ro from above % [arow,acol]= size(A); [row,col]= size(t); if(row == arow) P=t; else dif= arow-row; for i=1:dif temp=t; more=1; while (more==1) % % The trick i use to find arbitrary row that is L.I. with % those allready in Q, is by random generation, using the % built in magic function, I keep looping, generating random % rows untill i find one that is L.I., then i use it % temp1= magic(original_row); temp(new_ro_row+i,1:original_col)= temp1(1:1,1:original_col); [row,col]= size(orth(temp)); if(row == new_ro_row+i) more=0; t=temp; end end end P=t; end