5.0

5.0 | 1 rating Rate this file 4 Downloads (last 30 days) File Size: 2.07 KB File ID: #25363
image thumbnail

random unit vector generator

by Maxim Vedenyov

 

19 Sep 2009

ganerate random unit vectors |n|=1 isotropic

| Watch this File

File Information
Description

http://simulations.narod.ru/
Function random_unit_vector generate random vector. Number of vectors and dimentionarity are adjustable. Unzip and run test script zz_test_tmp.m. It compare result of random_unit_vector with simple generearion:
v= 2*rand(2,1)-1;
n=v/sqrt(v(1)^2+v(2)^2)
This simple generearion method has disadvantage: it is anisotropic. In 2d it has maximums in angular distribution for 45 135 225 315 degrees. random_unit_vector works in antother way:
v=randn;
n=v/sqrt(v(1)^2+v(2)^2)
Because normal distribution has property of that arguments in many dimentions combine into radius-vector:
f(x)=exp(-x^2);
f(y)=exp(-y^2);
F(x,y)=exp(-x^2)*exp(-y^2)=exp(-(x^2+y^2))
F(r)=exp(-r^2)*2*pi*r
then result of random_unit_vector isotropic
The function can generate many units vector of arbitrary dimention. Many units vectors-columns is in matrix. single/double precission adjustable. there is a excluding of discretization errors when |v| close to 0. Because randn function used only inside then contol random generator state by:randn('seed',1)
type
help random_unit_vector
to see all possible usings:
  random_unit_vector
  random_unit_vector(n)
  random_unit_vector(m,n)
  random_unit_vector([m n])
  random_unit_vector('double')
  random_unit_vector(n,'double')
  random_unit_vector(m,n,'double')
  random_unit_vector([m n],'double')
  random_unit_vector('single')
  random_unit_vector(n,'single')
  random_unit_vector(m,n,'single')
  random_unit_vector([m n],'single')

m - dimentionarity
n - number of unit vectors

Acknowledgements
This submission has inspired the following:
Global tsunami simulation GUI
MATLAB release MATLAB 7.6 (R2008a)
Other requirements Must work in any version of matlab.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
05 Jul 2010 Veronica WU  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
random unit vector Maxim Vedenyov 21 Sep 2009 10:48:53
isotropic Maxim Vedenyov 21 Sep 2009 10:48:53
rand Maxim Vedenyov 21 Sep 2009 10:48:53
randn Maxim Vedenyov 21 Sep 2009 10:48:53

Contact us at files@mathworks.com