필터 지우기
필터 지우기

How do I combine two different distributions in MATLAB?

조회 수: 6 (최근 30일)
James Newton
James Newton 2012년 9월 21일
Suppose I have X ~ Norm(x,y) and Y ~ Exponential(k)
I wish to create a new variable T = X + Y. How would this be done?
I need to be able to generate random numbers from the new variable T. Say I want to generate 1000 values how would I now do this?
Any help greatly appreciated.
Thanks.

채택된 답변

José-Luis
José-Luis 2012년 9월 21일
편집: José-Luis 2012년 9월 21일
your_fun = @(average,var,k,numRows,numCols) average + var.*randn(numRows,numCols) + exprnd(k,numRows,numCols)
And to get values:
your_vals = your_fun(3,2,5,10,10)
will give you a 10 x 10 matrix of random values.
  댓글 수: 5
José-Luis
José-Luis 2012년 9월 21일
편집: José-Luis 2012년 9월 22일
Well, I am sure there is an original paper defining the normal distribution, probably by Gauss, but any statistics book will give you the functions for both distributions. What James wanted was a random variable that is the sum of two other random variables. If you are talking about how the values are sampled, the default in Matlab is based on the Mersenne-Twister algorithm:
Matsumoto, M.; Nishimura, T. (1998). "Mersenne twister: a 623-dimensionally equidistributed uniform pseudo-random number generator". ACM Transactions on Modeling and Computer Simulation 8 (1): 3–30. doi:10.1145/272991.272995
The rest is just a more or less forward application of the formula (M-T will give you a value that you translate into a quantile that you then use to get your random value, using the formula that defines it).
Daniel Shub
Daniel Shub 2012년 9월 21일
@James, he could have done normrnd(mu,sigma,m,n), but it would be a hair slower because of the extra error checking.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

James Newton
James Newton 2012년 9월 21일
Thanks for the answer, it makes sense, forgot about making a function!

Community Treasure Hunt

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

Start Hunting!

Translated by