Probability density function of the uniform distribution

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


stats::uniformPDF(a, b)


stats::uniformPDF(a, b) returns a procedure representing the probability density function

of the uniform distribution on the interval [a, b].

The procedure f := stats::uniformPDF(a, b) can be called in the form f(x) with an arithmetical expression x. The return value of f(x) is either a floating-point number or a symbolic expression:

If x < a or x > b can be decided, then f(x) returns 0. If ax and xb can be decided, then f(x) returns the value 1/(b - a).

If x is a real floating-point number and both a and b can be converted to real floating-point numbers, then these values are returned as floating-point numbers. Otherwise, symbolic expressions are returned.

The function f reacts to properties of identifiers set via assume. If x is a symbolic expression with the property x < a, or x > b, or ax and xb, then the corresponding values are returned.

f(x) returns the symbolic call stats::uniformPDF(a, b)(x) if it cannot be decided whether x lies in the interval [a, b].

Numerical values for a and b are only accepted if they are real and ab.

Environment Interactions

The function is sensitive to the environment variable DIGITS which determines the numerical working precision.


Example 1

We evaluate the probability density function on the interval [- 3, 2 π] at various points:

f := stats::uniformPDF(-3, 2*PI):
f(-infinity), f(-PI), f(-3.0), f(1/2), f(0.5), f(PI), f(infinity)

delete f:

Example 2

If x is a symbolic object without properties, then it cannot be decided whether axb hold. A symbolic function call is returned:

f := stats::uniformPDF(a, b): f(x)

With suitable properties, it can be decided whether axb holds. An explicit expression is returned:

assume(x < a): f(x)

Note that assume(x < a) attached properties both to a and x. With the next call, we overwrite the property attached to x. However, the property attached to a has to be 'unassumed' as well to avoid inconsistent assumptions x < a and x > b:

unassume(a): assume(x > b): f(x)

assume(a <= x <= b): f(x)

assume(b > a): f(a + (b - a)/3)

unassume(x): unassume(a): unassume(b): delete f:

Example 3

We use symbolic arguments:

f := stats::uniformPDF(a, b): f(x)

When numerical values are assigned to a and b, the function f starts to produce numerical values:

a := 0: b := PI: f(3), f(3.0)

delete f, a, b:


a, b

arithmetical expressions representing real values; ab is assumed.

Return Values