unifstat
Continuous uniform mean and variance
Syntax
Description
Examples
Compute Mean and Variance
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
a
— Lower endpoint
numeric scalar | numeric vector | numeric array
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
b
— Upper endpoint
numeric scalar | numeric vector | numeric array
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
m
— Element-wise mean
numeric scalar | numeric vector | numeric array
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.
v
— Element-wise variance
numeric scalar | numeric vector | numeric array
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 (a –
b)2/12.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)