Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Uniform random rotation matrix
Date: Thu, 9 Dec 2010 21:13:20 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 34
Message-ID: <idrgpg$so6$1@fred.mathworks.com>
References: <idr87f$ho7$1@fred.mathworks.com> <idr8mi$q71$1@fred.mathworks.com> <idrfee$3iu$1@fred.mathworks.com> <idrg69$hrj$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1291929200 29446 172.30.248.37 (9 Dec 2010 21:13:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 9 Dec 2010 21:13:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:694024

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <idrg69$hrj$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <idrfee$3iu$1@fred.mathworks.com>...
> > "John D'Errico" <woodchips@rochester.rr.com> wrote in message <idr8mi$q71$1@fred.mathworks.com>...
> > > 
> > > [Q,R] = qr(rand(5));
> > > 
> > > Consider the properties of Q.
> > 
> > I'm almost sure using RAND will not produce "uniform" distribution of Q. RANDN will.
> > 
> > Bruno
> 
> True. The first vector will be a problem.
> However, with this slight change, it will do
> quite well...
> 
> [q,r]  = qr(rand(5)-.5);
> 
> John

On the other hand, is either of these methods
truly random in their result? Try this...

n = 100000;
ang = zeros(n,2);
for i= 1:n
  [q,~] = qr(rand(2) - 0.5);
  ang(i,1) = atan2(q(1,1),q(2,1));
  [q,~] = qr(randn(2) - 0.5);
  ang(i,2) = atan2(q(1,1),q(2,1));
end
hist(ang,100)

John