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 个评论

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).

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by