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

10 views (last 30 days)
Sebastian Raabe on 31 Oct 2021
Commented: Sebastian Raabe on 6 Nov 2021
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).
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 on 6 Nov 2021
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.
Sebastian Raabe on 6 Nov 2021
Hello Mike, thank you for your answer. I will try your proposal in the next few days.

### Categories

Find more on Linear Algebra in Help Center and File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!