Skip to content

Commit 47a1757

Browse files
committed
simplify elimination_matrix()
1 parent 03dac06 commit 47a1757

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/additional_functions/helper.jl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,17 @@ function duplication_matrix(nobs)
131131
return D
132132
end
133133

134-
function elimination_matrix(nobs)
135-
nobs = Int(nobs)
136-
n1 = Int(nobs * (nobs + 1) * 0.5)
137-
n2 = Int(nobs^2)
138-
L = zeros(n1, n2)
139-
140-
for j in 1:nobs
141-
for i in j:nobs
142-
u = zeros(n1)
143-
u[Int((j - 1) * nobs + i - 0.5 * j * (j - 1))] = 1
144-
T = zeros(nobs, nobs)
145-
T[i, j] = 1
146-
L += u * transpose(vec(T))
134+
# (n(n+1)/2)×n² matrix to transform a
135+
# vectorized form of a n×n symmetric matrix
136+
# into vector of its lower triangular entries,
137+
# opposite of duplication_matrix()
138+
function elimination_matrix(n::Integer)
139+
ntri = div(n * (n + 1), 2)
140+
L = zeros(ntri, n^2)
141+
for j in 1:n
142+
for i in j:n
143+
tri_ix = (j - 1) * n + i - div(j * (j - 1), 2)
144+
L[tri_ix, i+n*(j-1)] = 1
147145
end
148146
end
149147
return L

0 commit comments

Comments
 (0)