I want to solve the Lyapunov equation with matlab

9 views (last 30 days)
Why, when I calculate R, I don't find -I? Thank you."
% Définition des matrices du système
A = [0 1;0 0];% Remplacez ... par la matrice A de votre système
B=[2;5];
K=[-0.131 -1.6874];
Ak=A+B*K;
E = [1 2;0 0]; % Remplacez ... par la matrice E de votre système
I = eye(size(A)); % Matrice identité de même taille que A
Q = [1 0 ;0 1]; % Remplacez ... par une matrice Q définie positive
% Fonction pour résoudre l'équation de Lyapunov avec la condition E
lyapunov_solve = @(P) (Ak'*P*E + E'*P*Ak + I)
lyapunov_solve = function_handle with value:
@(P)(Ak'*P*E+E'*P*Ak+I)
% Initialisation de P
P0 = Q; % Vous pouvez également utiliser une autre initialisation si nécessaire
% Résolution de l'équation de Lyapunov avec la condition E
options = optimoptions('fsolve', 'Display', 'off'); % Options pour fsolve
Ps= fsolve(lyapunov_solve, P0, options)
Ps = 2×2
1.0881 -0.2826 -0.2826 1.0000
% Vérification de la positivité de P
if all(eig(Ps) > 0)
disp('La matrice P est définie positive.');
else
disp('La matrice P n''est pas définie positive.');
end
La matrice P est définie positive.
R =Ak'*Ps*E + E'*Ps*Ak
R = 2×2
-0.2000 -0.4000 -0.4000 -0.8000

Answers (2)

Torsten
Torsten on 27 Feb 2024
Use MATLAB's "lyap" or "dlyap".
  1 Comment
Christine Tobler
Christine Tobler on 28 Feb 2024
If you don't have Control Systems Toolbox, you can also look at the more generic sylvester function in base MATLAB.

Sign in to comment.


Torsten
Torsten on 28 Feb 2024
Edited: Torsten on 28 Feb 2024
You can also do it this way, but your system does not seem to have a solution:
% Définition des matrices du système
A = [0 1;0 0];% Remplacez ... par la matrice A de votre système
B=[2;5];
K=[-0.131 -1.6874];
Ak=A+B*K;
E = [1 2;0 0]; % Remplacez ... par la matrice E de votre système
I = eye(size(A)); % Matrice identité de même taille que A
Q = [1 0 ;0 1]; % Remplacez ... par une matrice Q définie positive
% Fonction pour résoudre l'équation de Lyapunov avec la condition E
P = sym('P',[2 2]);
eqns = Ak'*P*E + E'*P*Ak + I == 0;
[A,b] = equationsToMatrix(eqns)
A = 
b = 
sol = A\b
Warning: Solution does not exist because the system is inconsistent.
sol = 
lyap(Ak.',I,[],E.')
Error using lyap
The solution of this Lyapunov equation does not exist or is not unique.

Categories

Find more on Matrix Computations in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!