Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cofactor matrix

    Hi,

    I constructed a matrix using -matrix- command, and is there a way to find the cofactor matrix with a command?

    Thank you!

  • #2
    I cannot find a Mata function that does this, but you can easily calculate this by multiplying each element of the inverse by the determinant and transposing the resulting matrix. The inverse and determinant can be obtained using the functions -luinv()- and -det()-, respectively.

    Code:
    mata
    A = (1,2,3\0,4,5\1,0,6)
    A
    (det(A)*luinv(A))'
    end
    Res.:

    Code:
    : A = (1,2,3\0,4,5\1,0,6)
    
    : A
           1   2   3
        +-------------+
      1 |  1   2   3  |
      2 |  0   4   5  |
      3 |  1   0   6  |
        +-------------+
    
    : (det(A)*luinv(A))'
             1     2     3
        +-------------------+
      1 |   24     5    -4  |
      2 |  -12     3     2  |
      3 |   -2    -5     4  |
        +-------------------+
    Last edited by Andrew Musau; 09 Sep 2020, 15:47.

    Comment


    • #3
      Oh, I see!! Thank you very much.

      Can we use -det- and -luinv- to find the cofactor matrix of for instance, A_12?

      Comment


      • #4
        See

        Code:
        help matrix_extraction
        Directly, without creating the matrix, you can do something like

        Code:
        mata
        A = (1,2,3\0,4,5\1,0,6)
        A
        (det(A[1..2, 1..2])*luinv(A[1..2, 1..2]))'
        end
        Res.:

        Code:
        : A = (1,2,3\0,4,5\1,0,6)
        
        :
        : A
               1   2   3
            +-------------+
          1 |  1   2   3  |
          2 |  0   4   5  |
          3 |  1   0   6  |
            +-------------+
        
        :
        : (det(A[1..2, 1..2])*luinv(A[1..2, 1..2]))'
                1    2
            +-----------+
          1 |   4    0  |
          2 |  -2    1  |
            +-----------+

        Comment


        • #5
          Thank you very much!

          I will try this method!

          Comment

          Working...
          X