Skip to content

Instantly share code, notes, and snippets.

@StefanKarpinski
Created October 21, 2020 15:28
Show Gist options
  • Save StefanKarpinski/e57f5a36b7890b261a0d42db4eb1324c to your computer and use it in GitHub Desktop.
Save StefanKarpinski/e57f5a36b7890b261a0d42db4eb1324c to your computer and use it in GitHub Desktop.
using LinearAlgebra, Statistics
function randmatstat(t)
n = 5
v = zeros(t)
w = zeros(t)
a = zeros(n, n)
b = zeros(n, n)
c = zeros(n, n)
d = zeros(n, n)
P = zeros(n, 4n)
Q = zeros(2n, 2n)
PtP1 = zeros(4n, 4n)
PtP2 = zeros(4n, 4n)
QtQ1 = zeros(2n, 2n)
QtQ2 = zeros(2n, 2n)
for i = 1:t
a .= randn()
b .= randn()
c .= randn()
d .= randn()
P[:, 0n .+ (1:n)] .= a
P[:, 1n .+ (1:n)] .= b
P[:, 2n .+ (1:n)] .= c
P[:, 3n .+ (1:n)] .= d
Q[0n .+ (1:n), 0n .+ (1:n)] .= a
Q[0n .+ (1:n), 1n .+ (1:n)] .= b
Q[1n .+ (1:n), 0n .+ (1:n)] .= c
Q[1n .+ (1:n), 1n .+ (1:n)] .= d
mul!(PtP1, P', P)
mul!(PtP2, PtP1, PtP1)
mul!(PtP1, PtP2, PtP2)
mul!(QtQ1, Q', Q)
mul!(QtQ2, QtQ1, QtQ1)
mul!(QtQ1, QtQ2, QtQ2)
v[i] = tr(PtP2)
w[i] = tr(QtQ2)
end
return std(v)/mean(v), std(w)/mean(w)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment