I would like some help with the following:
L2=10^9;
nP=10^6;
x(:,1)=L2.*rand(nP,1);
y(:,1)=L2.*rand(nP,1); % Select initial partice position randomly (only positive values) NS
z(:,1)= L2.*rand(nP,1);
for ip=1:nP
r1(ip,1)= sqrt(x(ip,1)^2 + y(ip,1)^2 + z(ip,1)^2); % distance from (0,0,0) for each iteration
while r1(ip,1)>=L2
x(ip,1)=L2.*rand(1,1);
y(ip,1)=L2.*rand(1,1); % Select initial partice position randomly (only positive values) NS
z(ip,1)=L2.*rand(1,1);
r1(ip,1)= sqrt(x(ip,1)^2 + y(ip,1)^2 + z(ip,1)^2);
end
end
The problems I face are:
1) Since the radius L2 is very big, when I multiply with L2 with rand I get values very close to the boundaries of the box (10^8 for example) and I want the particles uniformly distributed all around the sphere.
2) Also after I run the while command the resulting distributions are no more uniform.