Question: Implement a function Gauss ( A ) that takes a square matrix ( A ) as input, performs Gaussian elimination with partial pivoting
Implement a function GaussA that takes a square matrix A as input, performs Gaussian elimination with partial pivoting slide of Partpdf and returns the matrices P L U from the resulting mathrmPAmathrmLU factorization as output. Then, use your function to compute a mathrmPAmathrmLU factorization of the matrix A from Q
An incomplete MATLAB code is provided below.
A ;;; ;
PLU GaussA
function PLU GaussA Input: A in R R ntimesn
mnsizeA; get the dimensions of A
if m ~ n
errornot a square matrix'; s if A is not a square matrix, give an error message to the user
end
P eyen; L eyen; U A; & For now, set P and L as identity matrices and U as A We will overwrite their entries later,
for i :n
~maxindex maxabsUi:ni; s check where the largest element in absolute value in column i on or below the diagonal is located
r maxindex i ; s r is the index st uri is the largest element in absolute value in column i diagonal and below
if r ~ i
s if r is not equal to in we need to swap some rows
Uiri:n Urii:n;
Lir:i L;
P P;
end
for j i:n
Ljil;
;
end
end
end
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
