LUP Decomp with Partial Pivoting

19 views (last 30 days)
Rebecca Berkawitz
Rebecca Berkawitz on 31 Oct 2016
(1) Find L, U, and P using Gaussian Elimination with partial pivoting.
(2) Find the d, using forward substitution, by solving L d = P b
(3) Find the solution x using backward substitution by solving U x = d
Function: lup_decomp.m Write an m-file function called lup_decomp.m that decomposes a matrix A into L, U, and P. U is found using Gaussian Elimination with partial pivoting. To find P and L:
(1) Start with P = I, and L = 0
(2) We set the elements of L as we do in L U decomposition (using the factors calculated from Gaussian Elimination).
(3) Whenever we swap rows during the course of partial pivoting, we also swap the same rows in L and P.
(4) When we are all finished, we set the diagonal elements of L to 1. Inputs:
A The matrix to decompose
Outputs:
L The lower triangular matrix
U The upper triangular matrix
P The permutation matrix
Driver: ch2_1.m Solve the following system of equations using P
T L U decomposition:
−5 −3 −5 1 −2 1
5 1 −1 −4 3 −1
−4 −3 3 4 −4 3
0 −2 −3 2 −3 2
2 1 −2 −5 0 −1
1 3 1 2 4 0
x =
1 1 1 1
Print L, U, P, and x to the Command Window, and confirm you have the correct results using the lu built-in function in Ma t lab:
1 [ L U P ] = lu(A)
. . . . The driver isnt so important but this is what I have so far:
function [L, U, P]= lup_decomp(A)
%outputs of function L,U,P; function of matrix A
n= length(A);
L= eye(n);
U= zeros(n);
P= eye(n);
for k=1:n-1
[~,r]= max(abs(A(k:end,k)));
r= n-(n-k+1)+r;
A([k r], :)= A([r k],:);
P([k r],:)= P([r k],:);
L([k r],:)= L([r k],:);
L(k+1:n,k)= A(k+1:n,k)/A(k,k);
U(k,1:n)= A(k,1:n);
A(k+1:n,1:n)= A(k+1:n,1:n)- L(k+1:n,k)*A(k,1:n);
end
U(:,end)= A(:,end);
end . . . ... .. I just have no idea where to go from here

Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!