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

20 vues (au cours des 30 derniers jours)
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

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by