Question: Hello, I need fix the following code for scaled partial pivoting Gauss elimination. This the main code function [ x ] = GEPP ( A
Hello, I need fix the following code for scaled partial pivoting Gauss elimination.
This the main code
functionxGEPPAb
xGEPPAb returns column vector x
Solves the linear system Axb using Gaussian Elimination with
Partial Pivoting GEPP
N~ sizeA; extracting number of rows
for k:N loop over rows of A
Amax Akk; maximum A is the pivot
p k; storing the existing row number into p
Next we test the nearest row that it is pivot larger than Akk
Finding the row if exist
for ik:N working under the pivot element all rows k to N
if absAikabsAmaxIs AikAmax if the element under the pivot larger than the pivot
Amax Aik; if yes, then Amaxthe larger element
p i; let p is the smallest integer rowin which condition is satisfied
end
end
if Amax then we can not evaluate its inverse
if absAmax
msgwarningMatrix is not invertible!;
throwmsg
end
Switching the two rows
if p not equal to k I do the switch of rows in b
PN if pk I do not need to switch, pivot is the largest
if p~k
temp bp; the bp is stored into temporary name
bp bk; bp is replaced by bk
bk temp;bk becomes bb
for j:N Similarly I switch the two rows in A
temp Apj;
Apj Akj;
Akj temp;
end
end
Next, do the multiplier formula, to make all elements under
the present diagonal pivot element to be equal to
for ik:N The constant vector b as well
bi biAikbkAkk;
for jk:N
Aij AijAikAkjAkk; AikAkjmij multiplier
end
Aik;
end
end
Back substitution
x zerosN; the solution is stored into x
for iN::
sum ;
for ji:N
sum sumAijxj;
end
xibisumAii;
end
end
Here My trying to fix it for scaled thankyou
functionxGEPPSAb
xGEPPAb returns column vector x
Solves the linear system Axb using Gaussian Elimination with
Partial Pivoting GEPP
N~ sizeA; extracting number of rows
for M:N
SMmaxabsAM:;
end
for k:N loop over rows of A
Scaled Partial pivoting
for ak:N
daabsAakSa;
end
Amax Akk; maximum A is the pivot
p k; storing the existing row number into p
Next we test the nearest row that it is pivot larger than Akk
Finding the row if exist
for ik:N working under the pivot element all rows k to N
if absAikabsAmaxIs AikAmax if the element under the pivot larger than the pivot
Amax Aik; if yes, then Amaxthe larger element
p i; let p is the smallest integer rowin which condition is satisfied
end
end
if Amax then we can not evaluate its inverse
if absAmax
msgwarningMatrix is not invertible!;
throwmsg
end
Switching the two rows
if p not equal to k I do the switch of rows in b
PN if pk I do not need to switch, pivot is the largest
if p~k
temp bp; the bp is stored into temporary name
bp bk; bp is replaced by bk
bk temp;bk becomes bb
for j:N Similarly I switch the two rows in A
temp Apj;
Apj Akj;
Akj temp;
end
end
Next, do the multiplier formula, to make all elements under
the present diagonal pivot element to be equal to
for M:N
SMmaxabsAM:;
end
for ik:N The constant vector b as well
bi biAikbkAkk;
for jk:N
Aij AijAikAkjAkk; AikAkjmij multiplier
end
Aik;
end
end
Back substitution
x zerosN; the solution is stored into x
for iN::
sum ;
for ji:N
sum sumAijxj;
end
xibisumAii;
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
