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?

 Réponse acceptée

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

5 commentaires

I do not think it is what I meant in the question.
James Tursa
James Tursa le 5 Avr 2018
Modifié(e) : James Tursa le 5 Avr 2018
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?
Z samples in each column and then Y rows. Thank you.
Maybe you could provide a small example of an output you want. E.g. for Y=2 and Z=3.
Let me work on it.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by