normpdf

Normal probability density function

Syntax

y = normpdf(x)
y = normpdf(x,mu)
y = normpdf(x,mu,sigma)

Description

example

y = normpdf(x) returns the probability density function (pdf) of the standard normal distribution, evaluated at the values in x.

y = normpdf(x,mu) returns the pdf of the normal distribution with mean mu and the unit standard deviation, evaluated at the values in x.

example

y = normpdf(x,mu,sigma) returns the pdf of the normal distribution with mean mu and standard deviation sigma, evaluated at the values in x.

Examples

collapse all

Compute the pdf values for the standard normal distribution at the values in x.

x = [-2,-1,0,1,2];
y = normpdf(x)
y = 1×5

    0.0540    0.2420    0.3989    0.2420    0.0540

Compute the pdf values evaluated at the values in x for the normal distribution with mean mu and standard deviation sigma.

x = [-2,-1,0,1,2];
mu = 2;
sigma = 1;
y = normpdf(x,mu,sigma)
y = 1×5

    0.0001    0.0044    0.0540    0.2420    0.3989

Compute the pdf values evaluated at zero for various normal distributions with different mean parameters.

mu = [-2,-1,0,1,2];
sigma = 1;
y = normpdf(0,mu,sigma)
y = 1×5

    0.0540    0.2420    0.3989    0.2420    0.0540

Input Arguments

collapse all

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

To evaluate the pdf at multiple values, specify x using an array. To evaluate the pdfs of multiple distributions, specify mu and sigma using arrays. If one or more of the input arguments x, mu, and sigma are arrays, then the array sizes must be the same. In this case, normpdf 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 mu and sigma, evaluated at the corresponding element in x.

Example: [-1,0,3,4]

Data Types: single | double

Mean of the normal distribution, specified as a scalar value or an array of scalar values.

To evaluate the pdf at multiple values, specify x using an array. To evaluate the pdfs of multiple distributions, specify mu and sigma using arrays. If one or more of the input arguments x, mu, and sigma are arrays, then the array sizes must be the same. In this case, normpdf 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 mu and sigma, evaluated at the corresponding element in x.

Example: [0 1 2; 0 1 2]

Data Types: single | double

Standard deviation of the normal 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 mu and sigma using arrays. If one or more of the input arguments x, mu, and sigma are arrays, then the array sizes must be the same. In this case, normpdf 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 mu and sigma, evaluated at the corresponding element in x.

Example: [1 1 1; 2 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, mu, and sigma after any necessary scalar expansion. Each element in y is the pdf value of the distribution specified by the corresponding elements in mu and sigma, evaluated at the corresponding element in x.

More About

collapse all

Normal Distribution

The normal distribution is a two-parameter family of curves. The first parameter, µ, is the mean. The second parameter, σ, is the standard deviation.

The standard normal distribution has zero mean and unit standard deviation.

The normal probability density function (pdf) is

y=f(x|μ,σ)=1σ2πe(xμ)22σ2,forx.

The likelihood function is the pdf viewed as a function of the parameters. The maximum likelihood estimates (MLEs) are the parameter estimates that maximize the likelihood function for fixed values of x.

Alternative Functionality

  • normpdf is a function specific to normal distribution. Statistics and Machine Learning Toolbox™ also offers the generic function pdf, which supports various probability distributions. To use pdf, create a NormalDistribution 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 normpdf 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.

References

[1] Evans, M., N. Hastings, and B. Peacock. Statistical Distributions. 2nd ed. Hoboken, NJ: John Wiley & Sons, Inc., 1993.

Extended Capabilities

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

Introduced before R2006a