Getting back the solution to Ax=b after reordering A
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Bruno Luong
el 20 de Oct. de 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 comentarios
Bruno Luong
el 21 de Oct. de 2019
Editada: Bruno Luong
el 21 de Oct. de 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)
Ver también
Categorías
Más información sobre Matrix Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!