필터 지우기
필터 지우기

how to assign random numbers that add up to equal 1

조회 수: 1 (최근 30일)
Hunter Herrenkohl
Hunter Herrenkohl 2019년 3월 10일
댓글: John D'Errico 2019년 3월 10일
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?

답변 (1개)

Walter Roberson
Walter Roberson 2019년 3월 10일
File Exchange, Roger's randfixedsum() and sort in descending order.
  댓글 수: 1
John D'Errico
John D'Errico 2019년 3월 10일
+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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by