2
$\begingroup$

I am working with matrices of which I need both the LinearSolveFunction and the determinant. My question is about something the documentation isn't entirely clear on. As far as I can tell, the LinearSolveFunction obtained from LinearSolve stores the LU decomposition of the matrix and from that it would be very easy to obtain the determinant.

mat = RandomReal[{-1, 1}, {3, 3}]
ls = LinearSolve[mat]
ls[[2, 3]]
Det[mat]
Tr[ls[[2, 3, 1]], Times]

However, the documentation mentions that:

When you create a LinearSolveFunction using LinearSolve[m], this often works by decomposing the matrix m into triangular forms, and sometimes it is useful to be able to get such forms explicitly."

So my question is: when use the above code, am I guaranteed that I will find the LU decomposition of my matrix when I evaluate ls[[2, 3]]? I can see that this is certainly not true when using other Methods in LinearSolve, but the default Automatic method seems to do have the LU decompositions there. Then again: the method being Automatic suggests that it might do something different depending on the matrix I put in.

So all being said and done: is there a good, reliable way to obtain the determinant from a LinearSolveFunction object?

$\endgroup$
2
  • $\begingroup$ A related math.SE question. $\endgroup$ Sep 24, 2017 at 11:09
  • $\begingroup$ It depends on the method used (esp. the non-LU ones, such as "Cholesky", "Banded", "Krylov", and even "Multifrontal", which seems to produce a nonstandard LU decomposition). $\endgroup$
    – Michael E2
    Mar 17, 2018 at 14:43

1 Answer 1

9
$\begingroup$

In this case, you will need to use some undocumented functionality:

Tr[ls["getU"], Times] Signature[ls["getPermutations"][[1]]]

(currently away from my computer, so I'm only using gedanken Mathematica)


Added much later

OK, apparently the "getPermutations" property is broken in version 11. In this case, we fall back on what you already know: that ls[[2, 3]] stores the equivalent of the result of LUDecomposition[]. Thus, adapting the solution in this answer:

mat = RandomReal[{-1, 1}, {3, 3}];
ls = LinearSolve[mat];
{lu, perm, cond} = ls[[2, 3]]
Signature[perm] Tr[lu, Times]

tho of course this assumes that the structure of LinearSolveFunction[] won't be changed too much, in which case one prolly should've used LUDecomposition[] to begin with.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.