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
function[x]=GEPP(A,b)
%[x]=GEPP(A,b), returns column vector x
% Solves the linear system Ax=b using Gaussian Elimination with
% Partial Pivoting (GEPP)
[N,~]= size(A); % extracting number of rows
for k=1:N % loop over rows of A
A_max = A(k,k); % 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 A(k,k)
%-------Finding the row if exist-------
for i=k+1:N % working under the pivot element all rows k+1 to N
if abs(A(i,k))>abs(A_max)%Is |A_{i,k}|>|A_max| if the element under the pivot larger than the pivot
A_max = A(i,k); % if yes, then Amax=the larger element
p = i; % let p is the smallest integer (row)in which condition is satisfied
end
end
%-----if A-max=0, then we can not evaluate its inverse-----
if abs(A_max)==0
msg=warning('Matrix is not invertible!');
throw(msg)
end
%%%%--------Switching the two rows---------
% if p not equal to k, I do the switch of rows in b
% PN (if p=k, I do not need to switch, pivot is the largest)
if p~=k
temp = b(p); % the b(p) is stored into temporary name
b(p)= b(k);% b(p) is replaced by b(k)
b(k)= temp;%b(k) becomes b(b)
for j=1:N % Similarly I switch the two rows in A
temp = A(p,j);
A(p,j)= A(k,j);
A(k,j)= temp;
end
end
%--------- Next, do the multiplier formula, to make all elements under
%the present diagonal (pivot) element to be equal to 0
for i=k+1:N % The constant vector b as well
b(i)= b(i)-A(i,k)*b(k)/A(k,k);
for j=k+1:N
A(i,j)= A(i,j)-A(i,k)*A(k,j)/A(k,k); % A_{i,k}/A{k,j}=m_{i,j} multiplier
end
A(i,k)=0;
end
end
%-----------Back substitution-----------
x = zeros(N,1); % the solution is stored into x
for i=N:-1:1
sum =0;
for j=i+1:N
sum = sum+A(i,j)*x(j);
end
x(i)=(b(i)-sum)/A(i,i);
end
end
_________________________________________________
Here My trying to fix it for scaled , thankyou
function[x]=GEPPS(A,b)
%[x]=GEPP(A,b), returns column vector x
% Solves the linear system Ax=b using Gaussian Elimination with
% Partial Pivoting (GEPP)
[N,~]= size(A); % extracting number of rows
for M=1:N
S(M)=max(abs(A(M,:)));
end
for k=1:N % loop over rows of A
%Scaled Partial pivoting
for a=k:N
d(a)=abs(A(a,k))/S(a);
end
A_max = A(k,k); % 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 A(k,k)
%-------Finding the row if exist-------
for i=k+1:N % working under the pivot element all rows k+1 to N
if abs(A(i,k))>abs(A_max)%Is |A_{i,k}|>|A_max| if the element under the pivot larger than the pivot
A_max = A(i,k); % if yes, then Amax=the larger element
p = i; % let p is the smallest integer (row)in which condition is satisfied
end
end
%-----if A-max=0, then we can not evaluate its inverse-----
if abs(A_max)==0
msg=warning('Matrix is not invertible!');
throw(msg)
end
%%%%--------Switching the two rows---------
% if p not equal to k, I do the switch of rows in b
% PN (if p=k, I do not need to switch, pivot is the largest)
if p~=k
temp = b(p); % the b(p) is stored into temporary name
b(p)= b(k);% b(p) is replaced by b(k)
b(k)= temp;%b(k) becomes b(b)
for j=1:N % Similarly I switch the two rows in A
temp = A(p,j);
A(p,j)= A(k,j);
A(k,j)= temp;
end
end
%--------- Next, do the multiplier formula, to make all elements under
%the present diagonal (pivot) element to be equal to 0
for M=1:N
S(M)=max(abs(A(M,:)));
end
for i=k+1:N % The constant vector b as well
b(i)= b(i)-A(i,k)*b(k)/A(k,k);
for j=k+1:N
A(i,j)= A(i,j)-A(i,k)*A(k,j)/A(k,k); % A_{i,k}/A{k,j}=m_{i,j} multiplier
end
A(i,k)=0;
end
end
%-----------Back substitution-----------
x = zeros(N,1); % the solution is stored into x
for i=N:-1:1
sum =0;
for j=i+1:N
sum = sum+A(i,j)*x(j);
end
x(i)=(b(i)-sum)/A(i,i);
end
end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!