Adding Permutation Matrix Into LU Factorization
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am working to create a function to do LU Factorization with partial pivoting. Through watching some videos, I created the code below, but I forgot to make the code return the permutation matrix and am having trouble adding it into the code. Any help with this would be greatly appreciated!
Thanks,
-Kyle
function f = mylu(A,b)
%%LU Decomposition
%Get Augmented Matrix
Ab=[A,b]
n = length(A);
L = eye(n);
P=eye(n)
%With A(1,1) as pivot Element
%Row exchange to make sure A(1,1) is the last in Column
col1=Ab(:,1);
[temp,idx] = max(col1);
temp = Ab(1,:);
Ab(1,:) = Ab(idx,:);
Ab(idx,:) = temp;
%Computation in the pivot column
for i=2:3;
alpha = Ab(i,1) / Ab(1,1);
L(i,1) = alpha;
Ab(i,:) = Ab(i,:) - alpha*Ab(1,:);
end
%With A(2,2) as pivot Element
%Row exchange to ensure A(2,2) is the largest in column 2
col2 = Ab(2:end,2);
[temp,idx] = max(col2);
temp = Ab(2,:);
Ab(2,:) = Ab(idx,:);
Ab(idx,:) = temp;
for i=3;
alpha = Ab(i,2) / Ab(2,2);
L(i,2) = alpha
Ab(i,:) = Ab(i,:) - alpha*Ab(2,:);
end
U=Ab(1:n,1:n)
end
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Eigenvalues & Eigenvectors finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!