Pivoting Gaussian Elimination Coding

I am trying to code a Pivoting Gaussian Elimination code using the algorithm that is posted in the picture. However, on the first iteration under the 2nd for loop(i=...) it is changing A(1,1) to 0 and not A(2,1). Below is the code:
if true
[n,m] = size(A);
[d,p] = sort(A(:,1),'descend');
for k =1:n-1
for i = k + 1:n
z = A(p(i),k) / A(p(k),k);
A(p(i),k) = 0
for j = k + 1:n
A(p(i),j) = A(p(i),j) - z*A(p(k),j);
end
end
end
end

1 commentaire

Aveek Podder
Aveek Podder le 20 Fév 2018
Hi,
p(2) is equals 1 that is the reason why A(p(i),k) = 0 is assigning A(1,1) = 0 instead of A(2,1).

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by