Partial pivoting row swapping
29 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rabia Sonmez
am 11 Sep. 2021
Kommentiert: Rabia Sonmez
am 13 Sep. 2021
a=[1 4 3 5;2 0 2 6;1 1 0 5;1 2 3 4];
b=[5;6;7;10]
ab=[a b]
for i=1,3
if ab(i,i)< abs(max(ab(:,i)))
piv=ab(i,:)
ab(i,:)=ab(i+1,:)
ab(i+1,:)=piv
for j=2:4
ab(j,:)=ab(j,:)-ab(j,1)/ab(1,1)*ab(1,:)
end
end
end
Guys when I run the code I get
ab =
2 0 2 6 6
0 4 2 2 2
0 1 -1 2 4
0 2 2 1 7
I should make zero below the diagonal matrix. I did firs column but the others I could not. Can you help me? Thank you in advance.
0 Kommentare
Akzeptierte Antwort
Chunru
am 12 Sep. 2021
a=[1 4 3 5;2 0 2 6;1 1 0 5;1 2 3 4];
b=[5;6;7;10]
ab=[a b]
for i=1:size(ab, 1)-1
% pivoting
[~, imax] = max(abs(ab(i:end, i)));
%ab(i:end, i)
%imax
% exchange rows
piv=ab(imax+(i-1),:);
ab(imax+(i-1), :)=ab(i, :);
ab(i, :)=piv;
ab
% elimination
for j=i+1:size(ab, 1)
ab(j,:)=ab(j,:)-ab(j,i)/ab(i,i)*ab(i,:)
end
end
4 Kommentare
Chunru
am 12 Sep. 2021
[~, imax] = max() is to find which element has the maximum. doc max for details.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!