Random vector generation

  • Follow


How to generate independent identically distributed random vectors of finite length using MATLAB?
0
Reply Govindarajan 9/22/2010 4:11:19 AM

"Govindarajan Jagannathan" <govind.ipr@gmail.com> wrote in message <i7bvl7$4id$1@fred.mathworks.com>...
> How to generate independent identically distributed random vectors of finite length using MATLAB?

The rand function produces uniformly distributed random numbers. 
randn produces normally-distributed numbers. 

Does that help?

Ross
0
Reply Ross 9/22/2010 5:15:07 AM


"Govindarajan Jagannathan" <govind.ipr@gmail.com> wrote in message <i7bvl7$4id$1@fred.mathworks.com>...
> How to generate independent identically distributed random vectors of finite length using MATLAB?

Please define "finite length".

If you want a uniform distribution in the ball { x in R^d : |x| <= rmax }, then this should do:

d = 3; % dimension
rmax = 3; %
n = 1000; % number of vectors

v = randn(d,n);
r = (rand(1,n)*rmax^d).^(1/d);
c = r./sqrt(sum(v.^2,1));
v = bsxfun(@times, v, c);

Bruno
0
Reply b.luong5955 (6337) 9/22/2010 5:27:04 AM

This might convince the above code works - at least in 2D:

d = 2; % dimension
rmax = 5;
n = 10000; % number of vectors

v = randn(d,n);
r = rmax * rand(1,n).^(1/d);
c = r./sqrt(sum(v.^2,1));
v = bsxfun(@times, v, c);

plot(v(1,:),v(2,:),'.')
axis equal

% Bruno
0
Reply Bruno 9/22/2010 5:36:04 AM

Thank you very much for both the messages. I will try them out.

govind

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i7c4k4$ods$1@fred.mathworks.com>...
> This might convince the above code works - at least in 2D:
> 
> d = 2; % dimension
> rmax = 5;
> n = 10000; % number of vectors
> 
> v = randn(d,n);
> r = rmax * rand(1,n).^(1/d);
> c = r./sqrt(sum(v.^2,1));
> v = bsxfun(@times, v, c);
> 
> plot(v(1,:),v(2,:),'.')
> axis equal
> 
> % Bruno
0
Reply Govindarajan 9/22/2010 11:58:07 AM

Thank you for the information, Ross. It sure does help.

--govind

"Ross W" <rosswoodskiwi@hotmail.com> wrote in message <i7c3cr$7dd$1@fred.mathworks.com>...
> "Govindarajan Jagannathan" <govind.ipr@gmail.com> wrote in message <i7bvl7$4id$1@fred.mathworks.com>...
> > How to generate independent identically distributed random vectors of finite length using MATLAB?
> 
> The rand function produces uniformly distributed random numbers. 
> randn produces normally-distributed numbers. 
> 
> Does that help?
> 
> Ross
0
Reply Govindarajan 9/22/2010 12:00:20 PM

5 Replies
306 Views

(page loaded in 0.03 seconds)

Similiar Articles:













7/24/2012 2:55:23 AM


Reply: