我在Matlab中使用了这段代码:Lambda = lyap(Cbar,Cbar,-2*Cbarprime);但是,Matlab显示错误消息:The solution of this Sylvester equation does not exist or is not unique.如何强制它输出任何一个解决方案?
function X = mysylvester(A,B,C)
% Solve the equation A*X + X*B = C
A = (A + A') / 2;
B = (B + B') / 2;
[QA, dA] = eig(A, 'vector');
[QB, dB] = eig(B, 'vector');
CC = QA'*C*QB;
tmp = dA + dB';
idx = find(abs(tmp) <= 0.00001);
tmp(idx) = inf;
X = CC ./ tmp;
X = QA*X*QB';
end
1条答案
按热度按时间e0uiprwp1#
我们可以使用下面的代码,它是通过将矩阵dA+dB'中的一些元素(实际上是零元素)改为inf而从官方函数
sylvester
修改而来的。