How to generate a random data vector that follows a constraint
Mostrar comentarios más antiguos
I want to generate random data vector
where
that follows this constrainst.
where
and
is a constant. I would appreciate any help.
where
is a constant. I would appreciate any help.Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 29 de Sept. de 2019
0 votos
Look in the File Exchange for Roger's randfixedsum(). Generate a vector with fixed sum
. Multiply all of the elements by rand() to implement the <= part. (Though you might want to worry about the difficulty that rand() is never exactly 1, so if you generate a sum exactly equal to
and multiply by rand() then the result can never exactly total 
3 comentarios
Bruno Luong
el 29 de Sept. de 2019
Editada: Bruno Luong
el 29 de Sept. de 2019
IIUC you propose
E = rand()*Etotal * randfixedsum(N,1,1,0,1)
this will generate bad distribution (too many point close to 0 compare to uniform distribution), espetially for N >> 1.
Walter Roberson
el 29 de Sept. de 2019
I was thinking of
rand() * randfixedsum(N,1,Etotal,0,Etotal)
but your comment might still apply.
Bruno Luong
el 29 de Sept. de 2019
Editada: Bruno Luong
el 29 de Sept. de 2019
Both give the same non-uniform pdf
The "correct" one is
E = rand()^(1/N)*Etotal * randfixedsum(N,1,1,0,1);
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
