MATLAB: Does the CANON function error out saying the system is uncontrollable, whereas it actually is controllable

Control System Toolbox

I am using the CANON function to compute the state-space canonical form of my system. I execute the following command:
G = [tf(1,[1 0]), tf(1,[1 0 0]), tf(1,[1 0 0 0])];
sys2 = ss(G,'min');
sys3 = canon(sys2,'companion')
I receive the following error when I execute the above code:
??? Error using ==> ss.canon at 108
System must be controllable from the first input.
However, I know for a fact that my system is controllable. My system is full rank as indicated by the following command:
rank(ctrb(sys2))
This returns a result '3', indicating that my system is full rank and hence controllable. However the CANON function errors out.

Best Answer

The reason why this error is received is because of the scaling of the A, B and C matrices of system 'sys2'. In this particular case, the entries in the A matrix, for example, range from 3.462e-061 to 0.7262.
Models that are such badly scaled usually come from converting a transfer function to state-space. However, the system is already in companion form, albeit the observable kind.
As mentioned in the help for the CANON function, transformations to companion form are numerically risky, and with a numerical range of entries in the A matrix, they are just hopeless, and hence the CANON algorithm breaks down. Similarly, any usage of RANK(CTRB(...)) is guaranteed to produce erroneous results.
Further, CTRB is an academic tool for students to work through simple textbook examples and is not suitable for serious computations. The HSVD or MINREAL functions are more appropriate for estimating the minimal order (all states are controllable and observable here, so controllability is not the issue).
If a very specific state-space form is required, the best approach would be to do the following:
1) Compute the numerator and denominator of sys
[n,d] = tfdata(sys,'v')
2) Using the formulas in any Control textbook, write the desired a,b,c,d matrices in terms of 'n' and 'd'.