How can I simulate data from an interval which needs to satisfy a constrain/condition?

5 ビュー (過去 30 日間)
I need to simulate uniformly data (two values: x and y) from an interval of possible numbers that obey a constrain/condition specified as A.x+B.y=M , where A,B and M are different given numbers. Specifically, suppose I have the following 3 constrains in the aforementioned notation: 2x+y=100 3x+2y=60 x+3y=80
Let's say that I need to generate 25 simulated data (i.e. 25 pairs of x and y) from EACH of these constrains. So, I would get 25 pairs, each of which will need to satisfy the respective constrain: 25 pairs for 2x+y=100; 25 pairs for 3x+2y=60, and 25 pairs for x+3y=80 Many thanks in advance

採用された回答

Matt Tearle
Matt Tearle 2012 年 10 月 26 日
編集済み: Matt Tearle 2012 年 10 月 26 日
Do you need to generalize this? Because for this case you could just do:
x = 20*rand(75,1);
y = x;
y(1:25) = 100 - 2*x(1:25);
y(26:50) = (60 - 3*x(26:50))/2;
y(51:75) = (80 - x(51:75))/3;
You could reshape into matrices or other arrangements if you want the three sets separately. E.g.
X = reshape(x,25,3);
Y = reshape(y,25,3);
  1 件のコメント
Paulo
Paulo 2012 年 10 月 29 日
Many many thanks for the precious help Matt! From what I can tell it should work. I'm now trying to use it with my data and if I encounter any other issues I will shout for help :-) All the best

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by