Getting back the solution to Ax=b after reordering A
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
When I run the code below, x does not equal to A\b i.e. the ordering is wrong. It is my understanding that x_ordered(P_amd) should reorder the elements according to [2 3 4 5 1] - is that incorrect?
clc
clear
close all
A=[4 1 2 0.5 2;1 0.5 0 0 0;2 0 3 0 0;0.5 0 0 5/8 0;2 0 0 0 16];
% P_amd=amd(A);
P_amd=[2 3 4 5 1];
A_ordered=A(P_amd,P_amd);
b=[1 2 3 4 5]';
b_ordered=b(P_amd);
A\b
x_ordered=A_ordered\b_ordered
x=x_ordered(P_amd)
0 commentaires
Réponses (1)
Bruno Luong
le 20 Oct 2019
This is correct:
clc
clear
close all
A=[4 1 2 0.5 2;1 0.5 0 0 0;2 0 3 0 0;0.5 0 0 5/8 0;2 0 0 0 16];
% P_amd=amd(A);
P_amd=[2 3 4 5 1];
A_ordered=A(P_amd,P_amd);
b=[1 2 3 4 5]';
b_ordered=b(P_amd);
x=A\b;
x=x(P_amd)
x_ordered=A_ordered\b_ordered
2 commentaires
Bruno Luong
le 21 Oct 2019
Modifié(e) : Bruno Luong
le 21 Oct 2019
Use the inverse of the permutation
clc
clear
close all
A=[4 1 2 0.5 2;1 0.5 0 0 0;2 0 3 0 0;0.5 0 0 5/8 0;2 0 0 0 16];
P_amd=[2 3 4 5 1];
A_ordered=A(P_amd,P_amd);
b=[1 2 3 4 5]';
b_ordered=b(P_amd);
x=A\b
x_ordered=A_ordered\b_ordered;
Pi_amd(P_amd) = 1:length(P_amd); % inverse of the permutation
x_ordered(Pi_amd)
Voir également
Catégories
En savoir plus sur Matrix Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!