Borrar filtros
Borrar filtros

how to assign random numbers that add up to equal 1

1 visualización (últimos 30 días)
Hunter Herrenkohl
Hunter Herrenkohl el 10 de Mzo. de 2019
Comentada: John D'Errico el 10 de Mzo. de 2019
I want to have a,b,c, and d all be random numbers greater than 0. I need a>bcd and b>cd. I also need the numbers to add up to 1. Is there anyway I can do this?

Respuestas (1)

Walter Roberson
Walter Roberson el 10 de Mzo. de 2019
File Exchange, Roger's randfixedsum() and sort in descending order.
  1 comentario
John D'Errico
John D'Errico el 10 de Mzo. de 2019
+1. but with a minor flaw: Note that c > d is not required by the problem statement. As such the set
[0.4, 0.3, 0.1, 0.2]
Should be allowed. So if the goal is purely that a > bcd and b > cd, then you need to randomly shuffle the two smallest elements after the sort to gain a truly valid set that will satisfy the requirements and sample the entire space uniformly.

Iniciar sesión para comentar.

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by