setting up a random vector that sums up to 1.

12 ビュー (過去 30 日間)
A123456
A123456 2016 年 2 月 7 日
コメント済み: Jos (10584) 2016 年 2 月 8 日
How can I set up a random vector that will sum up to 1.
  1 件のコメント
Jos (10584)
Jos (10584) 2016 年 2 月 8 日
Random vector of what? Values between 0 and 1? Integers between -Inf and +Inf?

サインインしてコメントする。

回答 (2 件)

John D'Errico
John D'Errico 2016 年 2 月 7 日
Congratulations! You are the 10 millionth person to ask this question. Sadly, the vector is not fully random if it sums to 1, as the elements are not independent, so beware of how you will choose to define "random". You will get many people answering you with a variety of schemes that do not yield uniformly random sets. So beware.
For example, I am confident that someone will choose to tell you to just generate a set of numbers using rand, then scale them by dividing by the sum. However, this does NOT generate sets that are uniformly distributed over the set of possible results.
So, is there a simple way to generate sets of N numbers that ARE uniformly distributed over all possible sets that do sum to 1? Yes, there is. In fact, there are at least a few ways to do so. A nice way to generate M sets of N numbers, with the requirement that they are uniformly distributed is this:
R = diff([zeros(M,1),rand(M,N-1),ones(M,1)],2);
Each row of R will be a set of N numbers. There are M rows.

Walter Roberson
Walter Roberson 2016 年 2 月 7 日

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by