views:

99

answers:

1

Description(this is a hwk question):

I am not sure where to start here. I plan to use Laplace's Expansion but I am not sure how to implement it for nxn matrices. Any help would be appreciated.

Note: I already have a function to generate random matrices for a nxn matrix. Also the timing the calculation isn't a problem. The only thing I have an issue is how to calculate the determinant.

Had to delete the question description b/c of my class policy.

+2  A: 

Ok, here's a hint.

  1. write a function to calculate the minor matrices. (hint, use slices)
  2. write a function to calculate the cofactors (this should call the first function, and the determinate function)
  3. the determinate function calls the function in step two and adds the results together. (hint: use sum)

viola, you have a determinant.

Also, don't forget that because of the way we write lists in python, the indices get reversed. That is if

M = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]

then m0,1 is 2 and not 4 as it would be in normal notation. you can think of it as a transpose or use zip

aaronasterling
So for the indexes the columns are counted first and then the rows?
Shagster_84
@shagster no, first the rows then the columns. Look at the code and think about it. (for me at least, the normal way to indice is column, row. "First you go down the hall then you go up the elevator") it's really a moot point here though because D(A^t) = D(A)
aaronasterling