simulation of a random variable

6 views (last 30 days)
Elena on 28 Jan 2015
Commented: Image Analyst on 28 Jan 2015
If i have a random variable Z=X+Y where X and Y are independent and continuous random variables, how can i sample/ simulate from Z using matlab?

Answers (2)

John D'Errico
John D'Errico on 28 Jan 2015
Edited: John D'Errico on 28 Jan 2015
Generate random variables X and Y independently, then add them.
I fail to see the problem here.
Assuming you know how to add, I suppose that maybe you don't know how to sample from a random variable. But since you have not told us what their distributions are, I'm not going to tell you how to sample from any possible general random variable. That would be a book to write, and not even a terribly small one.
There are tools in MATLAB to sample from random variables. The lookfor command would help you there to find them. You need to learn how to find things in MATLAB, so learn to use lookfor, and learn to use the help provided. For example, what does this do?
lookfor random
You might start with rand, a function that probably exists in almost any language.
Image Analyst
Image Analyst on 28 Jan 2015
Elena, if you're not wanting to use the uniform or Normal distribution, you can get nearly any one you can think of here:

Sign in to comment.

Star Strider
Star Strider on 28 Jan 2015
Do you want a value of Z>1? With the rand function, it is quite likely that you will get values of Z that are greater than 1, since rand produces values on the interval (0,1).
If you want to be certain that Z is always on the interval (0,1), divide the sum by 2:
Z = (X + Y)/2;


Find more on Entering Commands in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by