random numbers with mean-correction

14 visualizaciones (últimos 30 días)
Fernando
Fernando el 9 de Jun. de 2013
Hi,
I would like to generate random numbers with follow a normal distribution (randn) but mean-corrected with the following condition: sum(randon numbers)=K.
Where K is a constant.
Can anyone help me?
Thanks a lot.

Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Jun. de 2013

Más respuestas (1)

Roger Stafford
Roger Stafford el 9 de Jun. de 2013
In preference to the method in fileexchange/9700, (even though I wrote it,) I would suggest a method that exhibits a normal distribution on the hyperplane defined by K.
Suppose each vector (sample) of numbers which must have a sum of K has n components and you wish to generate N such random vectors. Do this:
u = repmat(K/n,n,1);
V = null(u.');
P = bsxfun(@plus,u,V*randn(n-1,N));
Each of the N columns of P has n numbers which always sum to K. In the n-1 dimensional hyperplane defined by this requirement, the points do have a multivariate normal distribution.
  1 comentario
Fernando
Fernando el 9 de Jun. de 2013
Ok, thanks a lot. I didn't know that way of generate random numbers neither the functions null and bsxfun.

Iniciar sesión para comentar.

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by