Hello everybody, I am a new user! I have a question regarding random sample generation in Matlab.
I have pdf function: 3/4(2x-x^2), x is on interval from 0 to 2. I have to generate sample that has the same distribution as mentioned before. What I have done so far: I calculated cdf by integrating and then obtained cdf^-1. I cannot solve the cdf^-1 equation for random x (from 0 to 1) as cdf^-1 is not solvable in Real numbers.
Am I doing something wrong? Any help would be greatly appreciated! Thanks in advance, Klemen.

 채택된 답변

Roger Stafford
Roger Stafford 2014년 2월 5일

0 개 추천

The cdf you obtained was presumably F(x) = -1/4*x^3+3/4*x^2. It is quite possible to solve for its inverse, since that involves only the solution of the cubic equation
-1/4*x^3+3/4*x^2 = p
This particular cubic can be solved as follows:
p = rand;
a = atan2(2*sqrt(p*(1-p)),1-2*p);
x = 1+2*cos(a/3-2*pi/3);
You can verify this by checking that x always lies between 0 and 2 and comparing -1/4*x^3+3/4*x^2 with p in a number of cases.
Therefore you can generate n random values with the desired distribution as follows:
p = rand(n,1);
a = atan2(2*sqrt(p.*(1-p)),1-2*p);
x = 1+2*cos(a/3-2*pi/3);

댓글 수: 1

Klemen
Klemen 2014년 2월 5일
Thank you very much! The described solution worked flawlessly.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

2014년 2월 4일

댓글:

2014년 2월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by