Can I calculate the inverse of a matrix using arrayfun?
1 view (last 30 days)
I have a sparse matrix A. I want to calculate its inverse. I used the following way to calculate invA.
invA = A \ speye(size(A));
My matrix size is 3000 by 3000. I found it took me 1.3 seconds to get invA. It is longer than I expected.
I am wondering if I could use arrayfun to calculate invA. The idea is to calculate each column in invA by invA(:,i) = A \ ei, where ei is a zero column vector except its ith element is 1.0.
I tried the following code to implement the above idea:
invA = arrayfun(@(x) A\x ,speye(size(A,1)));
But I got error message.
Thanks a lot.
More Answers (1)
Sulaymon Eshkabilov on 25 Jun 2021
Edited: Sulaymon Eshkabilov on 25 Jun 2021
In fact, you can employ arrayfun for the matric inverse calc, e.g.:
Note that arrayfun is not the best option and does not take the sparse matrix.
Just direct inv() is the fastest so far.
In fact, for solving linear systems, to compute the inverse is not advised.