Decompose Matrix A with PLU-Decomposition - Numerical Analysis

Click For Summary

Homework Help Overview

The discussion revolves around the PLU decomposition of a matrix, specifically focusing on understanding a provided Matlab code snippet that implements this decomposition. Participants are exploring the definitions and implications of PLU decomposition in the context of numerical analysis.

Discussion Character

  • Exploratory, Conceptual clarification, Problem interpretation, Assumption checking

Approaches and Questions Raised

  • Participants are questioning the purpose of specific lines in the code, such as why the loop runs to n-1 and what the row swapping operations are achieving. There are also inquiries about the definition of PLU decomposition and the programming language used.

Discussion Status

The discussion is ongoing, with some participants providing clarifications about the code and its structure. Others are seeking more information from the original poster to facilitate better assistance.

Contextual Notes

There are concerns about the clarity and completeness of the original poster's question, which may hinder effective assistance. The original poster is encouraged to provide additional context and details regarding the matrix they are attempting to decompose.

hgylfason
Messages
1
Reaction score
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
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
 
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.
 
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
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 28 ·
Replies
28
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K