Gamma PDF
y = distfun_gampdf ( x , a , b )
a 1x1 or nxm matrix of doubles, the outcome, greater or equal to zero
a 1x1 or nxm matrix of doubles, the shape parameter, greater or equal to zero
a 1x1 or nxm matrix of doubles, the scale parameter, greater or equal to zero
a nxm 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:
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.
// 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","f(x)") legend(lgd); | ![]() | ![]() |