Decompose Matrix A with PLU-Decomposition - Numerical Analysis

In summary: Welcome to PF, hgylfason.In summary, you are supposed to decompose a matrix A with a PLU-decomposition. You have the text and are trying to understand some of the language. The text with % in front of it is in Icelandic, and doesn't matter. The function [P,L,U,r] = PUL_thattun(X) takes in a matrix X and returns P, L, U, and r. For each row, the function calculates the maximum value of abs(U(i:n, i))) and stores it in [tmp, j]. j is then incremented by 1 and s is subtracted from U(j, i)/U
  • #1
hgylfason
1
0
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;



please help
 
Physics news on Phys.org
  • #2
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
 
  • #3
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;

You have two questions about this code.

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.
 
  • #4
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
 

Related to Decompose Matrix A with PLU-Decomposition - Numerical Analysis

What is PLU-decomposition?

PLU-decomposition is a numerical method used to decompose a matrix A into three matrices, P, L, and U, such that PA = LU. P is a permutation matrix, L is a lower triangular matrix, and U is an upper triangular matrix.

Why is PLU-decomposition useful in numerical analysis?

PLU-decomposition is useful in numerical analysis because it allows us to solve systems of linear equations more efficiently. By decomposing a matrix into three simpler matrices, we can use simpler methods to solve the system, such as forward and backward substitution.

What are the benefits of using PLU-decomposition over other methods?

PLU-decomposition is beneficial because it is more stable and accurate than other methods, such as Gaussian elimination. It also allows for easier and more efficient computation, as the simpler matrices can be solved using standard algorithms.

How is PLU-decomposition performed?

PLU-decomposition is performed using a series of row operations on the original matrix A. These operations transform A into an upper triangular matrix, U. The permutation matrix P is created by keeping track of the row swaps performed during the row operations, and the lower triangular matrix L is created by reversing the row operations.

In what situations is PLU-decomposition most useful?

PLU-decomposition is most useful when solving systems of linear equations with multiple right-hand sides. It is also useful when the matrix A is large and sparse, as it can reduce the amount of computation needed compared to other methods.

Similar threads

  • Calculus and Beyond Homework Help
Replies
0
Views
501
  • Calculus and Beyond Homework Help
Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
28
Views
2K
Replies
1
Views
891
  • Programming and Computer Science
Replies
9
Views
1K
Replies
0
Views
545
  • Topology and Analysis
Replies
2
Views
2K
Replies
6
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
967
Back
Top