LU Factorization (with Partial Pivoting) Algo- rithm Development Rules / Suggest
ID: 1767296 • Letter: L
Question
LU Factorization (with Partial Pivoting) Algo- rithm Development Rules / Suggestions The following rules apply to ALL of our Algorithm Development Problems These are helpful when you are testing your function and we will grade you on them 1. You must use the correct function name. 2. Check number of function inputs and outputs (vector and scalar inputs) 3. Clear variables in workspace prior to running tests 4. If variable names are not given, use appropriate and consistent names 5. Check function for all possible number of inputs (use nargin during devel- opment to catch errors) 6. Run algorithm for at least 2 different input values 7. Check algorithm does not produce extraneous output 8. Comment code for readability LU Factorization Algorithm Develop a MATLAB function that determines the LU Factorization of a square matrix. Your algorithm must use partial pivoting. You must name the function luFactor to recieve credit. For full credit, you must include appropriate error checking. If you are confused about what would be appropriate or have questions, feel free to come to office hours! Inputs: . A - coefficient matrix Outputs . L - lower triangular matrix U - upper triangular matrix · P-the pivot matrixExplanation / Answer
function [L, U, P] = LU_credit(A) [m, n] = size(A); L=eye(n); P=eye(n); U=A; for k=1:m-1 pivot=max(abs(U(k:m,k))) for j=k:m if(abs(U(j,k))==pivot) ind=j break; end end U([k,ind],k:m)=U([ind,k],k:m) L([k,ind],1:k-1)=L([ind,k],1:k-1) P([k,ind],:)=P([ind,k],:) for j=k+1:m L(j,k)=U(j,k)/U(k,k) U(j,k:m)=U(j,k:m)-L(j,k)*U(k,k:m) end pause; end end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.