Solution to speed up loop with gamma distribution (gampdf)?

2 ビュー (過去 30 日間)
le duy nguyen
le duy nguyen 2019 年 1 月 22 日
コメント済み: le duy nguyen 2019 年 1 月 22 日
Dear readers,
Is there any solution to speed up this M-file if n = 1.000.000 ? Any help is much appreciate.
best regards,
Duy Nguyen
tic
% number of iteration
n = 1000;
% prepare parameters
a = 0; b = 100;
alpha = a+(b-a)*rand(n,1);
c = 0; d = 2000;
beta = c+(d-c)*rand(n,1);
% loop
t = 1:500;
TTD = zeros(numel(t),n);
for i = 1:n
TTD(:,i) = gampdf(t,alpha(i),beta(i));
end
toc
% Elapsed time is 1.082072 seconds.

採用された回答

Torsten
Torsten 2019 年 1 月 22 日
100 sec to beat:
faktor = 1.0./(beta.^alpha.*gamma(alpha));
for i = 1:n
TTD(:,i) = faktor(i)*t.^(alpha(i)-1.0).*exp(-t/beta(i));
end
  1 件のコメント
le duy nguyen
le duy nguyen 2019 年 1 月 22 日
Although there are tiny differences between two TTDs, this solution is perfect to me. Thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by