generate data from arbitrary probability random function
古いコメントを表示
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 件のコメント
Bruno Luong
2018 年 12 月 17 日
pdf not propertly normalized
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);
integral(f,0,100)
returns
1.0500
Bruno Luong
2018 年 12 月 17 日
And in addition pdf is negative
>> y=f(linspace(0,10));
>> min(y)
ans =
-0.0268
>>
Torsten
2018 年 12 月 17 日
Most probably, the coefficients in f are rounded.
hamidreza hamidi
2018 年 12 月 22 日
回答 (1 件)
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
2018 年 12 月 22 日
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.
カテゴリ
ヘルプ センター および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!