# Random Orthogonal Matrices

**URL:** https://discourse.julialang.org/t/random-orthogonal-matrices/9779
**Category:** Optimization (Mathematical)
**Created:** [March 17, 2018, 11:56pm UTC](https://discourse.julialang.org/t/random-orthogonal-matrices/9779 "2018-03-17T23:56:27Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [March 18, 2018, 9:59pm UTC](https://discourse.julialang.org/t/random-orthogonal-matrices/9779/7 "2018-03-18T21:59:29Z")

</div>

An easy way to draw from the Haar measure is to take the QR of a matrix of iid random normals, with `R` constrained to have a positive diagonal:

```julia
Q,R = qr(randn(m,n))
O = Q*Diagonal(sign.(diag(R)))

```

There are even faster ways to do this: see [Orthogonal matrix - Wikipedia](https://en.wikipedia.org/wiki/Orthogonal_matrix#Randomization)

---

_[View the full topic](https://discourse.julialang.org/t/random-orthogonal-matrices/9779)._
