det.m

来自「国外专家做的求解LMI鲁棒控制的工具箱,可以相对高效的解决LMI问题」· M 代码 · 共 41 行

M
41
字号
function d = det(X)
%DET (overloaded)

% Author Johan L鰂berg 
% $Id: det.m,v 1.2 2004/07/01 11:17:09 johanl Exp $  

n = X.n;
m = X.m;

if n~=m
    error('Matrix must be square.');
else
    switch n
        case 1
            d = X;
        case 2
            % Freakin overloading on multiplication doesn't work. Probalby
            % stupid code...
            Y1.type = '()';
            Y2.type = '()';
            Y3.type = '()';
            Y4.type = '()';
            Y1.subs = {1,1};
            Y2.subs = {2,2};
            Y3.subs = {1,2};
            Y4.subs = {2,1};
            d = subsref(X,Y1)*subsref(X,Y2)-subsref(X,Y3)*subsref(X,Y4);
        otherwise
            d = 0;
            Y.type = '()';
            for i = 1:n   
                Y.subs = {i,1};
                xi = subsref(X,Y);
                if ~isequal(xi,0)
                    Y.subs = {[1:1:i-1 i+1:1:n],2:n};
                    subX = subsref(X,Y);
                    d = d + (-1)^(i+1)*xi*det(subX);
                end
            end
    end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?