-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGaussElimination_std.m
72 lines (63 loc) · 2.29 KB
/
GaussElimination_std.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%{
***************************************************************************************
* Abstract: Get a linearly independent set of columns from a matrix X
* Uses: This file has been compiled using Matlab R2017b
* Author: Michael Vasquez Otazu
* Email: [email protected]
* History: V1.0 - first release
********************************* START LICENSE BLOCK *********************************
* The MIT License (MIT)
* Copyright (C) 2017 Michael Vasquez Otazu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above Copyright notice and this Permission Notice shall be included in all copies
* or substantial portions of the Software.
********************************** END LICENSE BLOCK **********************************
%}
function [Xsub,Xidx] = GaussElimination_std(G, X, tol)
%% Check if X has no non-zeros and hence no independent columns
if ~nnz(X)
Xsub=[]; Xidx=[];
return
end
%% Set tol, the rank estimation tolerance (default=1e-10)
if nargin<3, tol=1e-10; end
%% Orthogonal-triangular-decomposition so that X*E = Q*R
% Unitary Q, Upper-triangular R, Permutation E
[Q, R, E] = qr(X,0);
%% Set the dimension "v" of the Cycle Basis
v = G.numedges - G.numnodes + 1;
% This value can be also calculated as the "rank of the independent set"
%{
if ~isvector(R)
diagr = abs(diag(R)); % Diagonal matrix of R (with ABSolute values)
else
diagr = R(1);
end
r = [find(diagr >= tol*diagr(1), 1, 'last')] -1 ;
%}
%% Select linearly-independent columns
[X_rows, X_cols] = size(X);
[R_rows, R_cols] = size(R);
elemN = 0;
idx = 1;
Xsub = zeros(X_rows,0);
Xidx = [];
while (elemN < v & idx < X_cols)
if R(R_rows, idx) == 0
tmp = X(:,idx);
Xsub = [Xsub tmp];
Xidx = [Xidx idx];
elemN = elemN + 1;
end
idx = idx + 1;
end
%Xidx = sort(E(1:r));
%Xsub = X(:,Xidx);
return
end