function [C, O] = ccom(A,b,c)
%CCOM Canonical form Controllability and Observability Matrices
%
%Given a system described in state space by A, b, c, and d
%with a transfer function of Poly(numerator)/Poly(denominator),
%this program computes two matrices C and O such that
% inv(C)*A*C and O*A*inv(O) generate a canonical companion form of A
%with the (-) denominator coefficients in a row or column and
% inv(C)*b and c*inv(O) generate a canonical [0 0 ... 0 1] form and
% c*C and O*b generate a canonical form
%containing the numerator coefficients when d=0.
%
%usage: [C, O] = ccom(A,b,c)
%
%tested with version 6.5.0.18 (R13)
%
%see also: CTRB, OBSV, ss, tf, compan, place, acker, pzplace
%
%Paul Godfrey
%March 29, 2007
%corrected a help typo
if nargin<1
clc
help ccom
return
end
debug=0;
b=b(:);
c=c(:).';
n=length(A);
C=[b];
O=[c];
for k=2:n
C=[b A*C];
O=[c; O*A];
end
p=poly(eig(A));
M=fliplr(triu(toeplitz(p(1:n))));
C=C*M;
O=M*O;
if debug==1
t=tf(ss(A,b,c,0))
inv(C)*A*C
inv(C)*b
c*C
disp(' ')
disp(' ')
O*A*inv(O)
O*b
c*inv(O)
end
return