Getting back the solution to Ax=b after reordering A
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Bruno Luong
2019-10-20
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 个评论
Bruno Luong
2019-10-21
编辑:Bruno Luong
2019-10-21
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!