Index: mttroot/mtt/lib/control/PPP/ppp_are.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_are.m +++ mttroot/mtt/lib/control/PPP/ppp_are.m @@ -11,15 +11,27 @@ if nargin<7 A_type = "feedback"; endif - + [n_x,n_u,n_y] = abcddim(A,B,C,D); # Dimensions + n_q = is_square(Q); # Size of Q + if n_q==0 + error("Q must be square"); + endif + ## Steady-state Linear Quadratic solution ## using Algebraic Riccati equation (ARE) - Q_x = C'*Q*C; # Weighting on x - [k, P, poles] = lqr (A, B, Q_x, R); # Algebraic Riccati solution + if n_q==n_y # Output weight + Q_x = C'*Q*C; # Weighting on x + elseif n_q==n_x # State weight + Q_x = Q; + else + error(sprintf("Q (%ix%i) must be %ix%i or %ix%i",n_q,n_q,n_y,n_y,n_x,n_x)); + endif + Q_x + [k, P, poles] = lqr (A, B, Q_x, R) # Algebraic Riccati solution ## Basis functions if strcmp(A_type,"companion") A_u = compan(poly(poles)); elseif strcmp(A_type,"feedback")