Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.
Vectors with random orientation
Posted Feb 19, 2016, 5:01 p.m. EST Parameters, Variables, & Functions 8 Replies
Please login with a confirmed email address before reporting spam
I'm interested to generate random vectors for the initial condition of my 3D model which is basically for solving time-dependent PDEs. The problem is the components of these vectors are random but sum of squares (which is the magnitude of the vectors) should be constant. In other words, I need to generate vectors with same magnitude but with random orientations. So the question is if I can do this in COMSOL using built in random function or any other ways without going through the hassle of using MATLAB.
Please login with a confirmed email address before reporting spam
Please login with a confirmed email address before reporting spam
a'=a/sqrt(a^2+b^2+c^2)
b'=b/sqrt(a^2+b^2+c^2)
c'=c/sqrt(a^2+b^2+c^2)
Please login with a confirmed email address before reporting spam
Please login with a confirmed email address before reporting spam
This is a decent approximation, but you don't get a uniform distribution over set of directions.
Do you know any alternatives?
Please login with a confirmed email address before reporting spam
Do you know any alternatives?
For a mathematical question such as yours I think that Google is a faster way to find an answer than this forum: Search for e.g. "random vector sphere".
Please login with a confirmed email address before reporting spam
Let's say the magnitude of the vector is equal to N and the direction of the vector varies with time.
For 2D simulation, I think one can create a random function (named rn1) with uniform distribution that ranges from -pi to pi (or 0 to 2*pi). By doing so, the x-compnent and y-compoent of the vector correspond to N*cos(rn1(t)) and N*sin(rn1(t)).
As for 3D simulation, I think it is just in analogy to spherical coordinate. If one creates two random functions both ranging from -pi to pi, then
x-component: N*sin(rn1(t))*cos(rn2(t))
y-component: N*sin(rn1(t))*sin(rn2(t))
z-component: N*cos(rn1(t))
Am I right about this?
Please login with a confirmed email address before reporting spam
No, that's not correct. Things are different on a sphere!
Being curious I followed Gunnar's advice and in less than a minute I found: mathworld.wolfram.com/SpherePointPicking.html
wolfram.com is frequently a very good resource for mathematics.
Cheers
Edgar
--
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Please login with a confirmed email address before reporting spam
Thanks for your reply. I finally know how to solve problem correctly.
Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.
