I am supposed to write a program to decompose matrix A with PLU-decomposition.(adsbygoogle = window.adsbygoogle || []).push({});

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 Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Numerical Analysis

**Physics Forums | Science Articles, Homework Help, Discussion**