What is the difference between lu() and decomposition([],'lu')?

조회 수: 5 (최근 30일)
Sebastian Raabe
Sebastian Raabe 2021년 10월 31일
댓글: Sebastian Raabe 2021년 11월 6일
Hello Matlab-Community,
I have a matrix (called SystemMatrix see atteched file) which I want to decompose in L and U. Matlab has 2 functions to do this:
  1. [L,U] = lu(A)
  2. da = decomposition(A,'lu').
If I run the following code on my PC I can see that decomposition(,'lu') is much faster than lu() (about a factor of 137).
load('SystemMatrix.mat')
disp('Loading done')
disp('Start LU decomposition with lu()')
tic
[L,U] = lu(SystemMatrix);
toc
Elapsed time is 30.138829 seconds.
disp('Start LU decomposition with decomposition([],''lu'')')
tic
da = decomposition(SystemMatrix,'lu');
toc
Elapsed time is 0.221673 seconds.
This is only a smaller example of my system matrix. If I want to decompose my full matrix, than lu() uses more than 32 GB of RAM (the calculation stops because out of memory), while decomposition(,'lu') uses only 10 to 13 GB of RAM and is finished after ca. 1 minute.
Here are my questions:
Why is decomposition(A,'lu') so much faster than lu(A)? Didn't they use the same algorithm?
Is there any way to get L and U from the decomposition object da? Because I want to solve an equation system with the same coefficient matrix several times (in parallel on different Computers) and I don't want to decompose the matrix on every Computer again.

채택된 답변

Mike Croucher
Mike Croucher 2021년 11월 6일
The two output form of lu() does use a different algorithm compared to the decomposition object. Also, it is not possible to save the results of a decomposition object.
The reasons for both of these facts are a little complex and I’m not well qualified to answer them. However, once way to solve your problem would be use the 4 or 5 output forms of lu() which use similar algorithms to decomposition:
[L,U,P,Q,D] = lu(SystemMatrix)
The extra matrices P,Q,D are defined in the lu() documentation. These can be used to solve your system and could be saved for use on multiple machines as you describe.
Timings on my machine are:
>> tic;[L,U] = lu(SystemMatrix);toc
Elapsed time is 19.708687 seconds.
>> tic;da = decomposition(SystemMatrix,'lu');toc
Elapsed time is 0.221085 seconds.
>> tic;[L,U,P,Q,D] = lu(SystemMatrix);toc
Elapsed time is 0.255020 seconds.
  댓글 수: 1
Sebastian Raabe
Sebastian Raabe 2021년 11월 6일
Hello Mike, thank you for your answer. I will try your proposal in the next few days.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by