generate data from arbitrary probability random function

조회 수: 2 (최근 30일)
hamidreza hamidi
hamidreza hamidi 2018년 12월 17일
댓글: Torsten 2019년 1월 2일
HI,
I Have a arbitrary probility function and I want to generate data according to this function
my function is:
f=7.6*exp(-2.1*x)+1.6*exp(-1.8*x)*cos(2.2*x+1.3)+9.4*exp(-2.04*x)*cos(x-2.6)
how can I generate data from this probability density function?
if I generate this data I would like to plot histogram of the generated data.
  댓글 수: 4
Torsten
Torsten 2018년 12월 17일
Most probably, the coefficients in f are rounded.
hamidreza hamidi
hamidreza hamidi 2018년 12월 22일
I estimated this function and x is between 0 and 20

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

답변 (1개)

Torsten
Torsten 2018년 12월 17일
편집: Torsten 2018년 12월 17일
n = 1000;
ur = zeros(n,1);
u = rand(n,1);
f = @(x)7.6*exp(-2.1*x)+1.6*exp(-1.8*x).*cos(2.2*x+1.3)+9.4*exp(-2.04*x).*cos(x-2.6);
for i = 1:numel(u)
fun = @(x)integral(f,0,x)-u(i);
ur(i) = fzero(fun,0.5);
end
histogram(ur)
  댓글 수: 2
hamidreza hamidi
hamidreza hamidi 2018년 12월 22일
can I have an interval? for example data with x between 0 and 10?
Torsten
Torsten 2019년 1월 2일
Adapt your probability function such that the integral from 0 to 10 equals 1 (e.g by dividing f(x) by integral_{0}^{10} f(x) dx).
Then the above method will produce random numbers between 0 and 10.
Best wishes
Torsten.

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

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by