**You are now following this question**

- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.

# Can I calculate the inverse of a matrix using arrayfun?

1 view (last 30 days)

Show older comments

Dear All,

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.

Benson

##### 1 Comment

### Accepted Answer

Walter Roberson
on 25 Jun 2021

Edited: Walter Roberson
on 25 Jun 2021

invA = cell2mat(arrayfun(@(C) A\sparse(C,1,1,size(A,1),1), 1:size(A,2), 'uniform', 0))

I would be surprised if it is faster.

##### 8 Comments

Walter Roberson
on 25 Jun 2021

A = sprand(20,20, .01)

A =

(5,2) 0.2696
(4,4) 0.9628
(9,5) 0.0991
(18,17) 0.8745

tic

invA = cell2mat(arrayfun(@(C) A\sparse(C,1,1,size(A,1),1), 1:size(A,2), 'uniform', 0))

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

invA =

(1,1) NaN
(3,1) NaN
(6,1) NaN
(7,1) NaN
(8,1) NaN
(9,1) NaN
(10,1) NaN
(11,1) NaN
(12,1) NaN
(13,1) NaN
(14,1) NaN
(15,1) NaN
(16,1) NaN
(18,1) NaN
(19,1) NaN
(20,1) Inf
(1,2) NaN
(3,2) NaN
(6,2) NaN
(7,2) NaN
(8,2) NaN
(9,2) NaN
(10,2) NaN
(11,2) NaN
(12,2) NaN
(13,2) NaN
(14,2) NaN
(15,2) NaN
(16,2) NaN
(18,2) NaN
(19,2) Inf
(20,2) NaN
(1,3) NaN
(3,3) NaN
(6,3) NaN
(7,3) NaN
(8,3) NaN
(9,3) NaN
(10,3) NaN
(11,3) NaN
(12,3) NaN
(13,3) NaN
(14,3) NaN
(15,3) NaN
(16,3) NaN
(18,3) Inf
(19,3) NaN
(20,3) NaN
(1,4) NaN
(3,4) NaN
(4,4) 1.0387
(6,4) NaN
(7,4) NaN
(8,4) NaN
(9,4) NaN
(10,4) NaN
(11,4) NaN
(12,4) NaN
(13,4) NaN
(14,4) NaN
(15,4) NaN
(16,4) NaN
(18,4) NaN
(19,4) NaN
(20,4) NaN
(1,5) NaN
(2,5) 3.7094
(3,5) NaN
(6,5) NaN
(7,5) NaN
(8,5) NaN
(9,5) NaN
(10,5) NaN
(11,5) NaN
(12,5) NaN
(13,5) NaN
(14,5) NaN
(15,5) NaN
(16,5) NaN
(18,5) NaN
(19,5) NaN
(20,5) NaN
(1,6) NaN
(3,6) NaN
(6,6) NaN
(7,6) NaN
(8,6) NaN
(9,6) NaN
(10,6) NaN
(11,6) NaN
(12,6) NaN
(13,6) NaN
(14,6) NaN
(15,6) NaN
(16,6) Inf
(18,6) NaN
(19,6) NaN
(20,6) NaN
(1,7) NaN
(3,7) NaN
(6,7) NaN
(7,7) NaN
(8,7) NaN
(9,7) NaN
(10,7) NaN
(11,7) NaN
(12,7) NaN
(13,7) NaN
(14,7) NaN
(15,7) Inf
(16,7) NaN
(18,7) NaN
(19,7) NaN
(20,7) NaN
(1,8) NaN
(3,8) NaN
(6,8) NaN
(7,8) NaN
(8,8) NaN
(9,8) NaN
(10,8) NaN
(11,8) NaN
(12,8) NaN
(13,8) NaN
(14,8) Inf
(15,8) NaN
(16,8) NaN
(18,8) NaN
(19,8) NaN
(20,8) NaN
(1,9) NaN
(3,9) NaN
(5,9) 10.0885
(6,9) NaN
(7,9) NaN
(8,9) NaN
(9,9) NaN
(10,9) NaN
(11,9) NaN
(12,9) NaN
(13,9) NaN
(14,9) NaN
(15,9) NaN
(16,9) NaN
(18,9) NaN
(19,9) NaN
(20,9) NaN
(1,10) NaN
(3,10) NaN
(6,10) NaN
(7,10) NaN
(8,10) NaN
(9,10) NaN
(10,10) NaN
(11,10) NaN
(12,10) NaN
(13,10) Inf
(14,10) NaN
(15,10) NaN
(16,10) NaN
(18,10) NaN
(19,10) NaN
(20,10) NaN
(1,11) NaN
(3,11) NaN
(6,11) NaN
(7,11) NaN
(8,11) NaN
(9,11) NaN
(10,11) NaN
(11,11) NaN
(12,11) Inf
(13,11) NaN
(14,11) NaN
(15,11) NaN
(16,11) NaN
(18,11) NaN
(19,11) NaN
(20,11) NaN
(1,12) NaN
(3,12) NaN
(6,12) NaN
(7,12) NaN
(8,12) NaN
(9,12) NaN
(10,12) NaN
(11,12) Inf
(12,12) NaN
(13,12) NaN
(14,12) NaN
(15,12) NaN
(16,12) NaN
(18,12) NaN
(19,12) NaN
(20,12) NaN
(1,13) NaN
(3,13) NaN
(6,13) NaN
(7,13) NaN
(8,13) NaN
(9,13) NaN
(10,13) Inf
(11,13) NaN
(12,13) NaN
(13,13) NaN
(14,13) NaN
(15,13) NaN
(16,13) NaN
(18,13) NaN
(19,13) NaN
(20,13) NaN
(1,14) NaN
(3,14) NaN
(6,14) NaN
(7,14) NaN
(8,14) NaN
(9,14) Inf
(10,14) NaN
(11,14) NaN
(12,14) NaN
(13,14) NaN
(14,14) NaN
(15,14) NaN
(16,14) NaN
(18,14) NaN
(19,14) NaN
(20,14) NaN
(1,15) NaN
(3,15) NaN
(6,15) NaN
(7,15) NaN
(8,15) Inf
(9,15) NaN
(10,15) NaN
(11,15) NaN
(12,15) NaN
(13,15) NaN
(14,15) NaN
(15,15) NaN
(16,15) NaN
(18,15) NaN
(19,15) NaN
(20,15) NaN
(1,16) NaN
(3,16) NaN
(6,16) NaN
(7,16) Inf
(8,16) NaN
(9,16) NaN
(10,16) NaN
(11,16) NaN
(12,16) NaN
(13,16) NaN
(14,16) NaN
(15,16) NaN
(16,16) NaN
(18,16) NaN
(19,16) NaN
(20,16) NaN
(1,17) NaN
(3,17) NaN
(6,17) Inf
(7,17) NaN
(8,17) NaN
(9,17) NaN
(10,17) NaN
(11,17) NaN
(12,17) NaN
(13,17) NaN
(14,17) NaN
(15,17) NaN
(16,17) NaN
(18,17) NaN
(19,17) NaN
(20,17) NaN
(1,18) NaN
(3,18) NaN
(6,18) NaN
(7,18) NaN
(8,18) NaN
(9,18) NaN
(10,18) NaN
(11,18) NaN
(12,18) NaN
(13,18) NaN
(14,18) NaN
(15,18) NaN
(16,18) NaN
(17,18) 1.1435
(18,18) NaN
(19,18) NaN
(20,18) NaN
(1,19) NaN
(3,19) Inf
(6,19) NaN
(7,19) NaN
(8,19) NaN
(9,19) NaN
(10,19) NaN
(11,19) NaN
(12,19) NaN
(13,19) NaN
(14,19) NaN
(15,19) NaN
(16,19) NaN
(18,19) NaN
(19,19) NaN
(20,19) NaN
(1,20) Inf
(3,20) NaN
(6,20) NaN
(7,20) NaN
(8,20) NaN
(9,20) NaN
(10,20) NaN
(11,20) NaN
(12,20) NaN
(13,20) NaN
(14,20) NaN
(15,20) NaN
(16,20) NaN
(18,20) NaN
(19,20) NaN
(20,20) NaN

toc

Elapsed time is 0.115353 seconds.

tic

invA = A\speye(size(A))

Warning: Matrix is singular to working precision.

invA =

(1,1) NaN
(3,1) NaN
(6,1) NaN
(7,1) NaN
(8,1) NaN
(9,1) NaN
(10,1) NaN
(11,1) NaN
(12,1) NaN
(13,1) NaN
(14,1) NaN
(15,1) NaN
(16,1) NaN
(18,1) NaN
(19,1) NaN
(20,1) Inf
(1,2) NaN
(3,2) NaN
(6,2) NaN
(7,2) NaN
(8,2) NaN
(9,2) NaN
(10,2) NaN
(11,2) NaN
(12,2) NaN
(13,2) NaN
(14,2) NaN
(15,2) NaN
(16,2) NaN
(18,2) NaN
(19,2) Inf
(20,2) NaN
(1,3) NaN
(3,3) NaN
(6,3) NaN
(7,3) NaN
(8,3) NaN
(9,3) NaN
(10,3) NaN
(11,3) NaN
(12,3) NaN
(13,3) NaN
(14,3) NaN
(15,3) NaN
(16,3) NaN
(18,3) Inf
(19,3) NaN
(20,3) NaN
(1,4) NaN
(3,4) NaN
(4,4) 1.0387
(6,4) NaN
(7,4) NaN
(8,4) NaN
(9,4) NaN
(10,4) NaN
(11,4) NaN
(12,4) NaN
(13,4) NaN
(14,4) NaN
(15,4) NaN
(16,4) NaN
(18,4) NaN
(19,4) NaN
(20,4) NaN
(1,5) NaN
(2,5) 3.7094
(3,5) NaN
(6,5) NaN
(7,5) NaN
(8,5) NaN
(9,5) NaN
(10,5) NaN
(11,5) NaN
(12,5) NaN
(13,5) NaN
(14,5) NaN
(15,5) NaN
(16,5) NaN
(18,5) NaN
(19,5) NaN
(20,5) NaN
(1,6) NaN
(3,6) NaN
(6,6) NaN
(7,6) NaN
(8,6) NaN
(9,6) NaN
(10,6) NaN
(11,6) NaN
(12,6) NaN
(13,6) NaN
(14,6) NaN
(15,6) NaN
(16,6) Inf
(18,6) NaN
(19,6) NaN
(20,6) NaN
(1,7) NaN
(3,7) NaN
(6,7) NaN
(7,7) NaN
(8,7) NaN
(9,7) NaN
(10,7) NaN
(11,7) NaN
(12,7) NaN
(13,7) NaN
(14,7) NaN
(15,7) Inf
(16,7) NaN
(18,7) NaN
(19,7) NaN
(20,7) NaN
(1,8) NaN
(3,8) NaN
(6,8) NaN
(7,8) NaN
(8,8) NaN
(9,8) NaN
(10,8) NaN
(11,8) NaN
(12,8) NaN
(13,8) NaN
(14,8) Inf
(15,8) NaN
(16,8) NaN
(18,8) NaN
(19,8) NaN
(20,8) NaN
(1,9) NaN
(3,9) NaN
(5,9) 10.0885
(6,9) NaN
(7,9) NaN
(8,9) NaN
(9,9) NaN
(10,9) NaN
(11,9) NaN
(12,9) NaN
(13,9) NaN
(14,9) NaN
(15,9) NaN
(16,9) NaN
(18,9) NaN
(19,9) NaN
(20,9) NaN
(1,10) NaN
(3,10) NaN
(6,10) NaN
(7,10) NaN
(8,10) NaN
(9,10) NaN
(10,10) NaN
(11,10) NaN
(12,10) NaN
(13,10) Inf
(14,10) NaN
(15,10) NaN
(16,10) NaN
(18,10) NaN
(19,10) NaN
(20,10) NaN
(1,11) NaN
(3,11) NaN
(6,11) NaN
(7,11) NaN
(8,11) NaN
(9,11) NaN
(10,11) NaN
(11,11) NaN
(12,11) Inf
(13,11) NaN
(14,11) NaN
(15,11) NaN
(16,11) NaN
(18,11) NaN
(19,11) NaN
(20,11) NaN
(1,12) NaN
(3,12) NaN
(6,12) NaN
(7,12) NaN
(8,12) NaN
(9,12) NaN
(10,12) NaN
(11,12) Inf
(12,12) NaN
(13,12) NaN
(14,12) NaN
(15,12) NaN
(16,12) NaN
(18,12) NaN
(19,12) NaN
(20,12) NaN
(1,13) NaN
(3,13) NaN
(6,13) NaN
(7,13) NaN
(8,13) NaN
(9,13) NaN
(10,13) Inf
(11,13) NaN
(12,13) NaN
(13,13) NaN
(14,13) NaN
(15,13) NaN
(16,13) NaN
(18,13) NaN
(19,13) NaN
(20,13) NaN
(1,14) NaN
(3,14) NaN
(6,14) NaN
(7,14) NaN
(8,14) NaN
(9,14) Inf
(10,14) NaN
(11,14) NaN
(12,14) NaN
(13,14) NaN
(14,14) NaN
(15,14) NaN
(16,14) NaN
(18,14) NaN
(19,14) NaN
(20,14) NaN
(1,15) NaN
(3,15) NaN
(6,15) NaN
(7,15) NaN
(8,15) Inf
(9,15) NaN
(10,15) NaN
(11,15) NaN
(12,15) NaN
(13,15) NaN
(14,15) NaN
(15,15) NaN
(16,15) NaN
(18,15) NaN
(19,15) NaN
(20,15) NaN
(1,16) NaN
(3,16) NaN
(6,16) NaN
(7,16) Inf
(8,16) NaN
(9,16) NaN
(10,16) NaN
(11,16) NaN
(12,16) NaN
(13,16) NaN
(14,16) NaN
(15,16) NaN
(16,16) NaN
(18,16) NaN
(19,16) NaN
(20,16) NaN
(1,17) NaN
(3,17) NaN
(6,17) Inf
(7,17) NaN
(8,17) NaN
(9,17) NaN
(10,17) NaN
(11,17) NaN
(12,17) NaN
(13,17) NaN
(14,17) NaN
(15,17) NaN
(16,17) NaN
(18,17) NaN
(19,17) NaN
(20,17) NaN
(1,18) NaN
(3,18) NaN
(6,18) NaN
(7,18) NaN
(8,18) NaN
(9,18) NaN
(10,18) NaN
(11,18) NaN
(12,18) NaN
(13,18) NaN
(14,18) NaN
(15,18) NaN
(16,18) NaN
(17,18) 1.1435
(18,18) NaN
(19,18) NaN
(20,18) NaN
(1,19) NaN
(3,19) Inf
(6,19) NaN
(7,19) NaN
(8,19) NaN
(9,19) NaN
(10,19) NaN
(11,19) NaN
(12,19) NaN
(13,19) NaN
(14,19) NaN
(15,19) NaN
(16,19) NaN
(18,19) NaN
(19,19) NaN
(20,19) NaN
(1,20) Inf
(3,20) NaN
(6,20) NaN
(7,20) NaN
(8,20) NaN
(9,20) NaN
(10,20) NaN
(11,20) NaN
(12,20) NaN
(13,20) NaN
(14,20) NaN
(15,20) NaN
(16,20) NaN
(18,20) NaN
(19,20) NaN
(20,20) NaN

toc

Elapsed time is 0.018112 seconds.

Benson Gou
on 25 Jun 2021

Hi, Walter,

Thanks for your help.

I compared your code and my original code. Your code took 3.7 sceonds while mine took 1.27 seconds.

I am wondering if there exists a faster code than my original code.

Thanks a lot, anyway.

Benso

Walter Roberson
on 25 Jun 2021

Benson Gou
on 25 Jun 2021

Hi, Walter,

Yes, decomposition is a good way to solve linear systems. But I need the inverse of the matrix for other calculations, not just solve the linear system.

Thanks a lot.

Benson

Walter Roberson
on 25 Jun 2021

You decompose the matrix. Then you use the decomposition on the left side of \ with speye() on the right hand side.

Most of the time you should not be using the inverse in calculations, and should instead be using the \ operator . inv(A)*b + inv(A)*c --> dA = decompose(A), dA\b +dA\c

Benson Gou
on 29 Jun 2021

Hi, Walter,

I do not have the Image Processing Toolbox. So I cannot run decompose(A).

But the goal that I want to obtain the inverse of A is becaus I need to find out the nonzero elements in invA. So I do not know if decompose(A) is able to be useful for my case.

Thanks a lot.

Benson

### 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.:

tic;

iA =arrayfun(@inv,A);

toc;

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.

##### 4 Comments

Walter Roberson
on 25 Jun 2021

A = sprand(20,20, .01)

A =

(16,5) 0.5706
(10,12) 0.5464
(12,16) 0.7549
(4,17) 0.6957

iA = arrayfun(@inv, full(A))

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

Warning: Matrix is singular to working precision.

iA = 20×20

Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.4373 Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.8301 Inf Inf Inf Inf Inf Inf Inf Inf

iA2 = 1./A

iA2 = 20×20

Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.4373 Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.8301 Inf Inf Inf Inf Inf Inf Inf Inf

Benson Gou
on 29 Jun 2021

Hi, Walter,

Yes, the decomposition is faster than \ operator. Thanks a lot.

Benson

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

### Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)