Main Content

unifstat

Continuous uniform mean and variance

Description

example

[m,v] = unifstat(a,b) returns the element-wise mean and variance of the continuous uniform distribution defined by the lower endpoint (minimum) a and upper endpoint (maximum) b. The endpoints a and b can be scalars, vectors, or multidimensional arrays.

Examples

collapse all

Compute the mean and variance of a continuous uniform standard distribution.

a = 0;
b = 1;
[m,v] = unifstat(a,b)
m = 0.5000
v = 0.0833

Create two vectors a and b, where a is the lower endpoint and b is the upper endpoint of a continuous uniform distribution. Return the mean m and variance v of the continuous uniform distribution defined by a and b.

a = 1:6;
b = 2*a;
[m,v] = unifstat(a,b)
m = 1×6

    1.5000    3.0000    4.5000    6.0000    7.5000    9.0000

v = 1×6

    0.0833    0.3333    0.7500    1.3333    2.0833    3.0000

If the lower endpoint a is greater than or equal to the upper endpoint b, unifstat returns NaN.

a = [1 2 3];
b = [3 2 1];
[m,v] = unifstat(a,b)
m = 1×3

     2   NaN   NaN

v = 1×3

    0.3333       NaN       NaN

Input Arguments

collapse all

Lower endpoint of the continuous uniform distribution, specified as a numeric scalar, vector, or array.

If a is a numeric vector or an array, then it must have the same size as b. If a is a numeric scalar, the function expands a to a constant matrix that has the same dimensions as b.

Example: [0 -1 7 9]

Data Types: single | double

Upper endpoint of the continuous uniform distribution, specified as a numeric scalar, vector, or array.

If b is a numeric vector or an array, then it must have the same size as a. If b is a numeric scalar, the function expands b to a constant matrix that has the same dimensions as a.

Example: [1 1 10 12]

Data Types: single | double

Output Arguments

collapse all

Element-wise mean of a continuous uniform distribution, returned as a numeric scalar, vector, or array.

Each element in m is the mean of a distribution specified by the corresponding elements in a and b. If a and b are not the same size, m is the size of a and b after any necessary scalar expansion. If a(i) is greater than or equal to b(i), then m(i) is NaN, where i is the index of an element. The mean of the continuous uniform distribution with endpoints a and b is (a + b)/2.

Element-wise variance of a continuous uniform distribution, returned as a numeric scalar, numeric vector, or numeric array.

Each element in v is the variance of a distribution specified by the corresponding elements in a and b. If a and b are not the same size, v is the size of a and b after any necessary scalar expansion. If a(i) is greater than or equal to b(i), then v(i) is NaN, where i is the index of an element. The variance of the continuous uniform distribution with endpoints a and b is (ab)2/12.

Extended Capabilities

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

Version History

Introduced before R2006a