simulation of a random variable
4 views (last 30 days)
Show older comments
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?
0 Comments
Answers (2)
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.
3 Comments
John D'Errico
on 28 Jan 2015
Of course it is possible. But since you have not told us what the distributions of X and Y are, then how can I know?
Are you asking that this be forced? Again, the distributions matter here. If that is a requirement, then the variables X and Y may not be independent in some circumstances. Again, without knowing the distributions, nothing is known.
Are you asking how to actually find those samples which exceeded 1, then just use the function find!
Be clear about your question. I think you really need to start reading the help though. There are good tutorials to be read, and you seem to be asking very basic questions.
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: http://www.mathworks.com/matlabcentral/fileexchange/7309-randraw
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;
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!