Main Content

unifpdf

Continuous uniform probability density function

Description

example

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

example

y = unifpdf(x,a,b) returns the pdf of the continuous uniform distribution on the interval [a, b], evaluated at the values in x.

Examples

collapse all

The pdf of the standard uniform distribution is constant on the interval [0,1].

Compute the pdf of 0.2, 0.4,...,1 in the standard uniform distribution.

x = 0.2:0.2:1;
y = unifpdf(x)
y = 1×5

     1     1     1     1     1

If x is not between a and b, unifpdf returns 0.

Compute the pdf of 1 through 5 in the continuous uniform distribution on the interval [2,4].

x2 = 1:5;
unifpdf(x2,2,4)
ans = 1×5

         0    0.5000    0.5000    0.5000         0

If the parameter a is larger than b, unifpdf returns NaN regardless of the x input.

unifpdf(5,10,1)
ans = NaN

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, unifpdf 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

Lower endpoint of the uniform 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 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, unifpdf 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: [0 -1 7 9]

Data Types: single | double

Upper endpoint of the uniform 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 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, unifpdf 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 10 10]

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

Continuous Uniform pdf

The continuous uniform distribution is a two-parameter family of curves with a constant pdf on its interval of support, [a, b]. The parameters a and b are the endpoints of the interval.

The continuous uniform pdf is

y=f(x|a,b)=1baI[a,b](x).

The standard uniform distribution occurs when a = 0 and b = 1.

For more information, see Uniform Distribution (Continuous).

Alternative Functionality

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

Introduced before R2006a