Getting the error "In the "lyap(A,Q,...)" command, A and Q must be square matrices of the same size." even though my A and Q matrix are the same size
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
So, I am trying to find the observability Gramian of a system using the 'lyap' function in MatLab. My code works for my controllability Gramian but not the observability. I have checked my inputs for my 'A' and 'Q' matricies (in my code they are called 'transpose(A)' and 'transpose(C)*C) and they are both 3x3 matricies and yet I am getting this error. I have copied my code below, if anyone has any ideas please let me know - thank you!
clc;
A = [-3 1 1;0 -2 1; 0 0 -1];
B = [2;2;1];
C = [1 -1 0];
% compute the controllability matrix
C_mat = ctrb(A,B);
%let's see if the system is controllable
if(length(A)==rank(C_mat))
fprintf('Controllable\n');
else
fprintf('System is not controllable\n');
end
% Compute controllable subspace
[~,new] = rref(C_mat);
disp('The controllable subspace is:')
C_subspace = C_mat(:, new)
% compute the observability matrix
O_mat = obsv(A,C);
%let's see if the system is controllable
if(length(A)==rank(O_mat))
fprintf('Observable\n');
else
fprintf('System is not observable\n');
end
% Compute controllable subspace
[~,new] = rref(O_mat);
disp('The observable subspace is:')
O_subspace = O_mat(new, :)
%%%Part B%%%
%Controllability Gramian
% C_gram=(-B*transpose(B))/(A+transpose(A))
C_gram=lyap(transpose(A),-B*transpose(B))
%Test if CG is nonsingular i.e. det = 0
det(C_gram) %matrix is singular
%Observability Gramian
O_gram=lyap(transpose(A),-C*transpose(C))
%Test if OG is nonsingluar
det(O_gram) %matrix is nonsingluar
%%%Part C%%%
null(O_gram)
0 commentaires
Réponses (1)
Walter Roberson
le 7 Déc 2020
Your code does not have transpose(C)*C. It has C*transpose(C)
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Computations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!