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!