How to find inverse of large size matrix.?

6 views (last 30 days)
HEmant kuralkar
HEmant kuralkar on 29 Jun 2017
Commented: Rik on 23 Aug 2019
I have a program in which I have need to find inverse of large size square matrix..e.g. [m n]=[800 800 ]
It takes longer to solve the program. I want to more effective and time saving way to solve that.
  1 Comment
Jan
Jan on 29 Jun 2017
Edited: Jan on 29 Jun 2017
Without knowing your code and what "longer" exactly means, how can we help you?

Sign in to comment.

Answers (2)

John D'Errico
John D'Errico on 29 Jun 2017
Edited: John D'Errico on 29 Jun 2017
800x800 is not even remotely large, IMO.
Everyone assumes that computers are infinitely fast, infinitely powerful, and that there are always tricks one can do to speed up any computation.
Computers are only as fast as they are. Computing the inverse of a matrix (something you almost never really need to do anyway, IF you know what you are doing) is a computation that takes a known number of adds, multiplies, etc. Your computer can only do those operations as fast as it can.
So, IF you truly need to compute an inverse and the time below is not fast enough for you, then...
A = rand(800);
timeit(@() inv(A))
ans =
0.054773
So it looks like my computer is a little faster than Jan's.
Regardless, if this is not fast enough, then you can get a faster computer. That is the best way to solve your problem. As you see, my computer solved the problem roughly 3 times as fast as did Jan's.
Next, you MIGHT be able to do things with sparse matrices, IF you know what you are doing, since you will need to not compute a direct inverse, AND IF your matrix is truly a sparse matrix. Many people think their matrices are sparse when they are not even close to sparse. The inverse of a sparse matrix will not in general be sparse, and so it may actually be slower to compute. So you will then need to reformulate the problem to avoid computing an inverse.
Of course, if you are able to reformulate the problem, then some things can yield speedups without too much effort. For example, an alternative to computing an inverse, is
B = eye(800);
timeit(@() A\B)
ans =
0.049547
As you can see here it gained about 10%, simply by using backslash instead of inv.
Other ideas might be to try moving the problem into your GPU. But that will require you have the parallel computing toolbox, AND learn how to use it effectively, and even then, I have no idea if you will see any real gain.
So the best way to see a speed increase is to get a faster computer. Or, get a cup of coffee and read a good book while you wait. If you want a better answer, it would help if we knew more about the matrices you are trying to invert, and specifically what you are doing with that inverse.
  10 Comments
Bruno Luong
Bruno Luong on 23 Aug 2019
"timeit calls the specified function multiple times, and computes the median of the measurements."
It seems redundant to loop on it
Rik
Rik on 23 Aug 2019
True, but there is still some spread, and since A is different every iteration, there is an extra source of variation. You could time @() inv(rand(800)) instead, but then you no longer have an idea about the spread, which could explain a fluke result.

Sign in to comment.


Jan
Jan on 29 Jun 2017
Edited: Jan on 29 Jun 2017
The explicite calculation of inverse is seldom necessary. Are you really sure you need it?
x = rand(800);
tic;
y = inv(x);
toc
% Elapsed time is 0.187157 seconds.
Do you need it much faster?

Tags

Products

Community Treasure Hunt

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

Start Hunting!