Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear
- clc
- close all
- exampleMatrix = [1, 3, -1 0, 4
- 4, 1, 7, 11, 5
- 0, 4, -4, -4, 4
- 2, 0 4 6, 2 ];
- [R_example,V_example]=rref(exampleMatrix)
- % reconstruct column in ExampleMatrix from a combination of the other
- % columns following example
- % https://math.stackexchange.com/questions/1624238/reduced-row-echelon-form-and-linear-independence
- % Entries in V contain pivot columns. Entry 3 does not appear in V, so it
- % is a nonpivot column. Loop through entries in column 3 of RREF(ExampleMatrix)
- % and use each as a coefficient to multiply the respective column in
- % ExampleMatrix by in order to obtain a linear combination that sums to the
- % column3 of
- originalColumn = zeros( [length(exampleMatrix(:,3)) 1] );
- for i=1:length(R_example(:,3))
- originalColumn = R_example(i,3)*exampleMatrix(:,i) + originalColumn;
- end
- originalColumn3ExampleMatrix=originalColumn
- actualColumn3ExampleMatrix=(exampleMatrix(:,3))
- % part 2: try the same thing with the crazy matrix
- A = [0 0 0 -2 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 -1 0 0 0 0 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 0
- 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 2 1 1 0 1
- -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0
- 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0
- 1 0 0 0 0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 1 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1];
- [R,V]=rref(A);
- % reconstruct row in A from a combination of the others
- % V contains the pivot columns.. need nonpivot columns, for now, let's just
- % take column 3 as an example
- % loop through entries in column 3 and see if I can get back the original
- % column...
- my_npc_index = 34;
- originalColumnFromLinearCombination = zeros( [length(A(:,my_npc_index)) 1] );
- counter=1;
- for i=1:length(R(:,my_npc_index))
- if (ismember(i,V))
- originalColumnFromLinearCombination = R(counter,my_npc_index)*A(:,i) + originalColumnFromLinearCombination;
- counter = counter+1;
- end
- end
- originalColumnFromLinearCombination
- actualOriginalColumn = A(:,my_npc_index)
- % SCRIPT OUTPUT
- % R_example =
- %
- % 1 0 2 3 1
- % 0 1 -1 -1 1
- % 0 0 0 0 0
- % 0 0 0 0 0
- %
- %
- % V_example =
- %
- % 1 2
- %
- %
- % originalColumn3ExampleMatrix =
- %
- % -1
- % 7
- % -4
- % 4
- %
- %
- % actualColumn3ExampleMatrix =
- %
- % -1
- % 7
- % -4
- % 4
- %
- %
- % originalColumnFromLinearCombination =
- %
- % 0
- % 1
- % 0
- % 0
- % 0
- % 1
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % -1
- % 0
- %
- %
- % actualOriginalColumn =
- %
- % 0
- % 1
- % 0
- % 0
- % 0
- % 1
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % 0
- % -1
- % 0
Advertisement
Add Comment
Please, Sign In to add comment