Simulating Gamma distributed RV's using Matlab
Show older comments
I am a beginner in Matlab and I need an explanation for this. I am trying to generate random variables that are gamma distributed and compare them with the output of gamcdf. I edited a code that does the same purpose with the exponential distribution but it seems that i made some mistakes.
n = 10000;
% inline function: gamma distributed random variables %generated by the sum of exponentials
randGamma = inline('-sum(log(rand(1,n)))/a', 'n', 'a');
a = 2
x = randGamma(n,a);
t = linspace(0, 5/a, 500);
figure
plot(sort(x), (1:n)/n, 'rx'), hold on
plot(t, gamcdf(t,a), 'k')
axis([0, max(t), 0, 1.1])
title(['Gammadistribution a = ', num2str(a)])
end
in the figures I get x is not showing up. I actually have a doubt in
plot(sort(x), (1:n)/n, 'rx'), hold on.
Can anyone please help me with that. I will have to do such an implementation with other distributions. So understanding this one will help me a lot. Thank you in advance
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!