Hello everyone, I have this figure which is shown below. I am getting a certain pattern of points every time i run my simulation. I mean, although the points are different every time but there is always some pattern in these points. Why is this, i don't know.

6 comentarios

José-Luis
José-Luis el 18 de Jun. de 2014
Sorry, but unless you give some more details, we are limited to venturing wild guesses. Also, this is not really a Matlab question.
Hi, i have this function for generating these points. And i want to have random points but not having any pattern in it.
function [posxy] = position(r, n, h)
ms = 10 * r;
ms = ms + 4 * sum(fix(sqrt(r^2-[1:r-1].^2)));
if n > ms
error('n exceeds the number of position.');
end
posxy = zeros(n,3);
for ii=1:n
while 1
xx = (r*rand) * sign(sin(2*pi*rand));
yy = (r*rand) * sign(cos(2*pi*rand));
if xx^2+yy^2 <= r^2 & (xx~=0 | yy~=0)
if length(find(posxy(:,1)==xx & posxy(:,2)==yy)) == 0
break
end
end
end
posxy(ii,[1 2]) = [xx yy];
if h == 1
while 1
posxy(ii,3) = round(50*rand) / 10;
if 1 <= posxy(ii,3) & posxy(ii,3) <= 4
break
end
end
end
end
Aftab Ahmed Khan
Aftab Ahmed Khan el 18 de Jun. de 2014
Also, what is "rand" in this code. I can't see anywhere its value then how it can be used here.
Star Strider
Star Strider el 18 de Jun. de 2014
The rand function returns uniformly-distributed pseudorandom numbers on the interval (0,1).
Aftab Ahmed Khan
Aftab Ahmed Khan el 18 de Jun. de 2014
Then why i am not getting something like this. I am again using the rand function.
Star Strider
Star Strider el 18 de Jun. de 2014
That is because xx and yy are scaled, so that the radius component is always on the interval (0,r) and the quadrant is defined by the sign of the sin and cos (respectively) of different random numbers, this time on the interval (0,2*pi), so those parts of the calculation are defined on the interval (-1,1).
The end result is that xx and yy are each independently defined on the same interval for both the radius and angle compoents, but are different because the values returned by rand are different. Here, it looks as though they will always end up on an angle that is some odd integer multiple of (pi/4) radians, with varying radii.
Those explain posxy(:,1:2). I don’t understand posxy(:3).

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 18 de Jun. de 2014

2 votos

Computer-generated random numbers aren’t really ‘random’ in the mathematical sense of ‘randomness’ because they depend on deterministic algorithms and finite word lengths to compute them. These also depend on where the random number generator starts (the ‘seed’ number). The term used to describe numbers generated by these algorithms is ‘pseudorandom’ for that reason.
MathWorks explains it better than I can, because they wrote the algorithms. See Random Numbers in MATLAB and Why Do Random Numbers Repeat After Startup? for details.

2 comentarios

Hi star,
I got this now for my starting question. There is no pattern in it now compare to my starting question. I achieved this by removing the sign function from below two lines of code. Can you explain to me what this function does over here. I understand what sign function does, but what does it do over here ?
xx = (r*rand) * sign(sin(2*pi*rand));
yy = (r*rand) * sign(cos(2*pi*rand));
Star Strider
Star Strider el 18 de Jun. de 2014
Here, the sign function forces the angle the radii are plotted against to always be an odd integer multiple of (pi/4) radians (45°).
Removing the sign function allows the angle to be defined randomly on the interval (0,2*pi).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Jun. de 2014

Comentada:

el 18 de Jun. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by