Created
January 20, 2015 16:34
-
-
Save 02015678/353ea94c27e4c5f89c9d to your computer and use it in GitHub Desktop.
Matlab program for LU Factorization with partial (row) pivoting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [L,U,P]=LU_pivot(A) | |
% LU factorization with partial (row) pivoting | |
% K. Ming Leung, 02/05/03 | |
[n,n]=size(A); | |
L=eye(n); P=L; U=A; | |
for k=1:n | |
[pivot m]=max(abs(U(k:n,k))); | |
m=m+k-1; | |
if m~=k | |
% interchange rows m and k in U | |
temp=U(k,:); | |
U(k,:)=U(m,:); | |
U(m,:)=temp; | |
% interchange rows m and k in P | |
temp=P(k,:); | |
P(k,:)=P(m,:); | |
P(m,:)=temp; | |
if k >= 2 | |
temp=L(k,1:k-1); | |
L(k,1:k-1)=L(m,1:k-1); | |
L(m,1:k-1)=temp; | |
end | |
end | |
for j=k+1:n | |
L(j,k)=U(j,k)/U(k,k); | |
U(j,:)=U(j,:)-L(j,k)*U(k,:); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello. I have a question. why you changed "L" matrix after k=1 ??
if k >= 2
temp=L(k,1:k-1);
L(k,1:k-1)=L(m,1:k-1);
L(m,1:k-1)=temp;
end