Getting back the solution to Ax=b after reordering A

조회 수: 3 (최근 30일)
Jeff Chen
Jeff Chen 2019년 10월 19일
편집: Bruno Luong 2019년 10월 21일
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)

답변 (1개)

Bruno Luong
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
Jeff Chen
Jeff Chen 2019년 10월 21일
Hi thanks for that,
A follow up question: I noticed you permuted x as well, but if Ax=b is the original system I want to solve, how would I go from x_ordered (solution to the reorderd system) to x, the solution to the original problem - this is the question I wanted to ask, sorry for the confusion.
Bruno Luong
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 CenterFile Exchange에서 Matrix Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by