Adding Permutation Matrix Into LU Factorization
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!