Index: mttroot/mtt/lib/control/PPP/ppp_lin.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_lin.m +++ mttroot/mtt/lib/control/PPP/ppp_lin.m @@ -174,16 +174,10 @@ for i = 1:m_t Ust = Us(i,:); J_uu = J_uu + Ust'*R*Ust; endfor - ## Exit if badly conditioned - cond_uu = cond(J_uu); - if cond_uu>max_cond - error(sprintf("J_uu is badly conditioned. Condition number = 10^%i",log10(cond_uu))); - endif - ## w bits if n_W>0 for i = 1:n_y # For each output QQ = ones(n_U,1)*Q(i,:); # Resize Q J_uw = J_uw + (QQ .* y_u(:,i:n_y:n_yu)') * Ws (:,i:n_y:n_yw); @@ -211,10 +205,17 @@ Y_0 = zeros(n_x,n_y); Y_0(1,:) = ones(1,n_y); x_W_t = obsv(A,C)\Y_0; endif J_uw = J_uw + x_u_t'*P*x_W_t; + + ## Exit if badly conditioned + cond_uu = cond(J_uu); + if cond_uu>max_cond + error(sprintf("J_uu is badly conditioned. Condition number = 10^%i",log10(cond_uu))); + endif + ## Compute the open-loop gains K_w = J_uu\J_uw; K_x = J_uu\J_ux;