Skip to content

Instantly share code, notes, and snippets.

@bicycle1885
Created July 4, 2019 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bicycle1885/0d8ac37956968ac4d0caa466fd595deb to your computer and use it in GitHub Desktop.
Save bicycle1885/0d8ac37956968ac4d0caa466fd595deb to your computer and use it in GitHub Desktop.
using LinearAlgebra: qr
function equilibrium(Q::AbstractMatrix)
@assert size(Q, 1) == size(Q, 2)
R = qr(Q').R
n = size(Q, 1)
v = zeros(eltype(Q), n)
v[end] = 1
for i in n-1:-1:1
s = zero(eltype(Q))
for j in i+1:n
s += R[i,j] * v[j]
end
v[i] = -s / R[i,i]
end
return v ./ sum(v)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment