使用Octave的决定因素的拉普拉斯展开

时间:2015-03-13 18:52:50

标签: recursion matrix octave

我试图在Octave中使用Laplace expansion来计算矩阵的行列式。我使用两个函数:

  • submatrix,获取submatrix给定矩阵和索引:

    function A = submatrix(A, i, j)
       A(i,:) = [];
       A(:,j) = [];
    endfunction
    
  • determinant,用于递归计算行列式:

    function d = determinant(A) 
        [m,n] = size(A);
    
        if m == 2
            # Base case are 2x2 matrices
            d = A(1,1)*A(2,2) - A(1,2)*A(2,1);
        else
            d = 0;
            for j = 1:n
                d = d + (-1).^(1+j)*determinant(submatrix(A,1,j));
            endfor
        endif
    endfunction
    

该函数可以正常使用3乘3矩阵,但对于更大的矩阵(4乘4和更大),它总是返回0(或-0)。

问题:为什么determinant对于大于3乘3的矩阵会返回0?

0 个答案:

没有答案