Question about Gaussian elimination about converting a matrix to a upper-triangle matrix

22 views (last 30 days)
function x=rowGauss(A,b)
[N,N]=size(A);
x=zeros(1,N+1);
Ag=[A,b];
for p=1:N-1
  [y,j]=max(abs(Ag(p:N,p)))
  C=Ag(p,:);
  Ag(p,:)=Ag(j+p-1,:);
  Ag(j+p-1,:)=c;
  if Ag(p,p)==0
      disp('Error')
      break;
  end
  for k=p+1:N
      m=Ag(k,p)/Ag(p,p);
      Ag(k,p:N+1)=Ag(k,p:N+1)-m*Ag(p,p:N+1);
  end
end
end

I have a question about the codes below

Ag(p,:)=Ag(j+p-1,:);
Ag(j+p-1,:)=c;
if Ag(p,p)==0

Find the maximum element then exchange with the pivot. But I think it should be like this:

 C=Ag(p,:);
 Ag(p,:)=Ag(j,:);
 Ag(j,:)=c; 

Could anybody tell me the difference? Thanks

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!