Generating samples of two dimensional random variable

First I want to generate a two-dimensional random variable (X1,X2) where X1 is from unif [0,1] and X2 is independently from unif [0,x1] and I want to generate a Y*2Z matrix where each row will consists of Z independent draws of (X1, X2). What will be a compact way to write this code?

 採用された回答

James Tursa
James Tursa 2018 年 4 月 5 日

0 投票

Y = something
Z = something
result = rand(Y,2*Z);
result(:,2:2:end) = result(:,2:2:end) .* result(:,1:2:end);

5 件のコメント

alpedhuez
alpedhuez 2018 年 4 月 5 日
I do not think it is what I meant in the question.
James Tursa
James Tursa 2018 年 4 月 5 日
編集済み: James Tursa 2018 年 4 月 5 日
The result from the above code consists of Z number of pairs of values (X1,X2) arranged in each of Y number of rows, where the 1st value in the pair X1 is from U(0,1), and the 2nd value in the pair X2 is from U(0,X1), the X1 being the 1st value in this particular pair. Isn't that what you asked for?
alpedhuez
alpedhuez 2018 年 4 月 6 日
Z samples in each column and then Y rows. Thank you.
James Tursa
James Tursa 2018 年 4 月 6 日
Maybe you could provide a small example of an output you want. E.g. for Y=2 and Z=3.
alpedhuez
alpedhuez 2018 年 4 月 7 日
Let me work on it.

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

その他の回答 (0 件)

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by