Sort by

recency

|

5 Discussions

|

  • + 0 comments

    matrix is only N=5, might as well bruteforce recurse

    A = [
      [3,0,0,-2,4],
      [0,2,0,0,0],
      [0,-1,0,5,-3],
      [-4,0,1,0,6],
      [0,-1,0,3,2]
    ]
    def det(A):
      N = len(A)
      if N == 1: return A[0][0]
      return sum(
        (-1)**i * v * det([[v for j,v in enumerate(ls) if j != i] for ls in A[1:]])
        for i,v in enumerate(A[0])
        if v
      )
    
    print(det(A))
    
  • + 0 comments

    It looks like my homework bruh print(-114)

  • + 0 comments

    -114

  • + 0 comments

    This is a relatively sparse matrix, so we might be able to solve it directly.

    1. Find any row or column that has only one non-zero value. The remaining zeros nullify any sub-matrix they might multiply, so the determinant must go through that value. Accordingly, we can zero out the rest of the column or row (note the reversal of terms) where a value is the only non-zero in its column or row. (There are two such.)
    2. Iterate #1 as far as possible. (This isolates a third row & column)
    3. The determinant of the remaining matrix is (relatively) easy to compute.
  • + 0 comments

    The answer is -114.

No more comments