# Numerical Analysis

I am supposed to write a program to decompose matrix A with PLU-decomposition.

I have this text and I am trying to understand some parts of it.

The text with % in front of it is in Icelandic and doesn´t matter.

function [P,L,U,r] = PUL_thattun(X)

n=length(X);
L = zeros(n,n);
U = X;
Pt = eye( n, n );

for i=1:(n-1) %(Why is it n-1 and not just n????)
% Staersta stak ad algildi valid sem vendistak
[tmp, j] = max(abs(U(i:n, i))) ;
j = j + (i - 1);

if ( tmp == 0 )
error( 'Not usable' );
end

%Skipta a 'i' og 'j'.

U ([i, j], :) = U ([j, i], :); %(What is this exactly doing????)
Pt([i, j], :) = Pt([j, i], :); %(What is this exactly doing????)
L ([i, j], :) = L ([j, i], :); %(What is this exactly doing????)

for j=(i + 1):n
s = -U(j, i)/U(i, i);
U(j, :) = U(j, :) + s*U(i, :);
L(j, i) = -s;
end
end
P = Pt
L = L + eye( n, n )
U = U
X = P*L*U;

First, what is a PLU decomposition? I am familiar with LU, QR, and Cholesky decomposition algorithms, but I have never heard of a PLU decomposition.

Second, what language is that mess of code written in?

Third, where is the matrix that you are trying to decompose?

Lastly, how do you honestly expect someone to help you out with this horribly written question? Please provide as much information as possible so that we can efficiently and effectively help you out.

I would like to help you out, but you haven't really given any information that will allow me to do that. So please provide all of the needed information so that I (we) can help you out.

Thanks
Matt

D H
Staff Emeritus
Welcome to PF, hgylfason.

CFDEADGURU: You could have searched for PLU decomposition. Google is your friend. Without pivoting, Crout's algorithm for the LU decomposition would be unstable. The P matrix is a permutation matrix that records this pivoting.

hgylfason: Your Matlab code is flush left. You didn't post it that way, but that is how it appears. We have a nice mechanism for displaying code with proper indentation.

Here is your code, presented as code:
Code:
function [P,L,U,r] = PUL_thattun(X)

n=length(X);
L = zeros(n,n);
U = X;
Pt = eye( n, n );

for i=1:(n-1)         %(Why is it n-1 and not just n????)
% Staersta stak ad algildi valid sem vendistak
[tmp, j] = max(abs(U(i:n, i))) ;
j = j + (i - 1);

if ( tmp == 0 )
error( 'Not usable' );
end

%Skipta a 'i' og 'j'.

U ([i, j], :) = U ([j, i], :);    %(What is this exactly doing????)
Pt([i, j], :) = Pt([j, i], :);    %(What is this exactly doing????)
L ([i, j], :) = L ([j, i], :);     %(What is this exactly doing????)

for j=(i + 1):n
s = -U(j, i)/U(i, i);
U(j, :) = U(j, :) + s*U(i, :);
L(j, i) = -s;
end
end
P = Pt
L = L + eye( n, n )
U = U
X = P*L*U;

First, the loop doesn't go to the last element because it doesn't need to. The LU decomposition of a 1x1 matrix is trivial.

Second, U ([i, j], :) = U ([j, i], :); is simply swapping the ith and jth rows of the matrix U.

CFDEADGURU: You could have searched for PLU decomposition

Yes, I am aware of that however, I wanted to get the definition from the user.

Thanks for your help D H.

Now I see that it is MatLab code. I couldn't tell exactly what code it was since it wasn't stated.

Thanks
Matt