Main Content

gampdf

Gamma probability density function

Description

example

y = gampdf(x,a) returns the probability density function (pdf) of the standard gamma distribution with the shape parameter a, evaluated at the values in x.

example

y = gampdf(x,a,b) returns the pdf of the gamma distribution with the shape parameter a and the scale parameter b, evaluated at the values in x.

Examples

collapse all

Compute the density of the observed value 5 in the standard gamma distribution with shape parameter 2.

y1 = gampdf(5,2)
y1 = 0.0337

Compute the density of the observed value 5 in the gamma distributions with shape parameter 2 and scale parameters 1 through 5.

y2 = gampdf(5,2,1:5)
y2 = 1×5

    0.0337    0.1026    0.1049    0.0895    0.0736

Input Arguments

collapse all

Values at which to evaluate the pdf, specified as a nonnegative scalar value or an array of nonnegative scalar values.

  • To evaluate the pdf at multiple values, specify x using an array.

  • To evaluate the pdfs of multiple distributions, specify a and b using arrays.

If one or more of the input arguments x, a, and b are arrays, then the array sizes must be the same. In this case, gampdf expands each scalar input into a constant array of the same size as the array inputs. Each element in y is the pdf value of the distribution specified by the corresponding elements in a and b, evaluated at the corresponding element in x.

Example: [3 4 7 9]

Data Types: single | double

Shape parameter of the gamma distribution, specified as a positive scalar value or an array of positive scalar values.

  • To evaluate the pdf at multiple values, specify x using an array.

  • To evaluate the pdfs of multiple distributions, specify a and b using arrays.

If one or more of the input arguments x, a, and b are arrays, then the array sizes must be the same. In this case, gampdf expands each scalar input into a constant array of the same size as the array inputs. Each element in y is the pdf value of the distribution specified by the corresponding elements in a and b, evaluated at the corresponding element in x.

Example: [1 2 3 5]

Data Types: single | double

Scale parameter of the gamma distribution, specified as a positive scalar value or an array of positive scalar values.

  • To evaluate the pdf at multiple values, specify x using an array.

  • To evaluate the pdfs of multiple distributions, specify a and b using arrays.

If one or more of the input arguments x, a, and b are arrays, then the array sizes must be the same. In this case, gampdf expands each scalar input into a constant array of the same size as the array inputs. Each element in y is the pdf value of the distribution specified by the corresponding elements in a and b, evaluated at the corresponding element in x.

Example: [1 1 2 2]

Data Types: single | double

Output Arguments

collapse all

pdf values evaluated at the values in x, returned as a scalar value or an array of scalar values. y is the same size as x, a, and b after any necessary scalar expansion. Each element in y is the pdf value of the distribution specified by the corresponding elements in a and b, evaluated at the corresponding element in x.

More About

collapse all

Gamma pdf

The gamma distribution is a two-parameter family of curves. The parameters a and b are shape and scale, respectively.

The gamma pdf is

y=f(x|a,b)=1baΓ(a)xa1exb,

where Γ( · ) is the Gamma function.

The standard gamma distribution occurs when b = 1.

For more information, see Gamma Distribution.

Alternative Functionality

  • gampdf is a function specific to the gamma distribution. Statistics and Machine Learning Toolbox™ also offers the generic function pdf, which supports various probability distributions. To use pdf, create a GammaDistribution probability distribution object and pass the object as an input argument or specify the probability distribution name and its parameters. Note that the distribution-specific function gampdf is faster than the generic function pdf.

  • Use the Probability Distribution Function app to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a