4.33333

4.3 | 3 ratings Rate this file 5 Downloads (last 30 days) File Size: 1.68 KB File ID: #13799

Gamma Random Variate Generator

by Simon Rogers

 

30 Jan 2007 (Updated 16 Nov 2007)

Gamma Random Variate Generator

| Watch this File

File Information
Description

Simple function to generate N random variates from a gamma distribution. Uses acceptance-rejection method, e.g. http://en.wikipedia.org/wiki/Gamma_distribution

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
13 Sep 2007 Huynh Hieu

Itis nice, thank

15 Nov 2007 Matt Hoffman

Nice not to have to do this myself. But your variable naming is a little confused in the file - in the source, you call theta beta. It's fine in the documentation, though, which is more important, I guess.

30 Jun 2010 Kan

It saves me when I am trying to use gamma distribution in Embedded Matlab. Since gamma distribution is not supported, I must generate the rv by myself. When coding in Embedded Matlab, the only thing needs to be modified is to assert a bound for "un" as follows:

assert (k <= 10000);
un = rand(1,k);
g = (theta)*(g - sum(log(un),2));

Please login to add a comment or rating.
Updates
16 Nov 2007

Updated source with consistent variable naming

Tag Activity for this File
Tag Applied By Date/Time
statistics Simon Rogers 22 Oct 2008 08:58:45
probability Simon Rogers 22 Oct 2008 08:58:45
statistics gamma random variates Simon Rogers 22 Oct 2008 08:58:45

Contact us at files@mathworks.com