Hi @Assen Beshr
Correct me if I interpreted your problem incorrectly. If you want to maximize the real part of the stabilizing eigenvalues (heading towards
) determined from the LQR algorithm, which requires finding the values of Q and R weights in the range
, then I arrive at this result using particleswarm() optimizer:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1555772/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1555777/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1555782/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1555787/image.png)
objfun = @costfun;
nvars = 3;
lb = [0.1 0.1 0.1];
ub = [10. 10. 10.];
nonlcon = [];
[K, fval] = particleswarm(objfun, nvars, lb, ub)
%% Check eigenvalues
A = [0 1; -1 -1];
B = [0; 1];
Q = [K(1) 0; 0 K(2)];
R = K(3);
K = lqr(A, B, Q, R);
eigvals = eig(A - B*K)
%% Cost function
function J = costfun(param)
A = [0 1; -1 -1];
B = [0; 1];
Q = [param(1) 0; 0 param(2)];
R = param(3);
K = lqr(A, B, Q, R);
eigvals = eig(A - B*K);
realeig = sortrows(real(eigvals));
J = - realeig(2); % Maximize the real part of eigenvalues
end