Gamma PDF
y = distfun_gampdf ( x , a , b )
a matrix of doubles, the outcome, x>=0
a matrix of doubles, the shape parameter, a>0.
a matrix of doubles, the scale parameter, b>0.
a matrix of doubles, the density
Computes the Gamma probability distribution function.
Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.
The function definition is:
Compatibility note.
This function is compatible with Matlab, but not compatible with R. Indeed, notice that b, the scale, is the inverse of the rate. Other computing languages (including R), use 1/b as the second parameter of the Gamma distribution. Hence, the calling sequence
distfun_gampdf(x,a,b)
corresponds to the R calling sequence:
dgamma(x,a,1/b)
// Test x scalar, a scalar, b expanded b = 1:5; computed = distfun_gampdf(1,1,b); expected = [.. 3.678794411714423340D-01 , .. 3.032653298563167121D-01 , .. 2.388437701912631272D-01 , .. 1.947001957678512196D-01 , .. 1.637461506155963586D-01 .. ]; // Test all expanded computed = distfun_gampdf([1 1],[2 2],[3 3]); expected = [.. 7.961459006375437575D-02 , .. 7.961459006375437575D-02 .. ]; // Plot the function shape = [1 2 3 5 9]; scale = [2 2 2 1 0.5]; cols = [1 2 3 4 5]; nf = size(cols,"*"); lgd = []; scf(); for k = 1 : nf x = linspace(0,20,1000); y = distfun_gampdf ( x , shape(k) , scale(k) ); plot(x,y) str = msprintf("shape=%s, scale=%s",.. string(shape(k)),string(scale(k))); lgd($+1) = str; end h = gcf(); for k = 1 : nf hcc = h.children.children; hcc.children(nf - k + 1).foreground = cols(k); end xtitle("Gamma PDF","x","y") legend(lgd); | ![]() | ![]() |