Probability distributions are statistical techniques. They are used to predict occurrences of random variables in a data set. These distributions are divided into various forms on the basis of their characteristics. One such probability distribution is the uniform distribution.
Manually finding statistics such as mean and variance of uniform distribution is not an easy task. However, in the era of MATLAB, we are blessed with a library containing plenty of built-in functions. This library has increased the performance and efficiency of such tasks by reducing their complexity.
This article presents:
What Are the Applications of Uniform Distribution?
How to Find Mean and Variance of Uniform Distribution in MATLAB?
How to Find Mean and Variance of Continuous Uniform Distribution in MATLAB?
- Example 1: How to Determine Mean and Variance of Continous Uniform Distribution Corresponding to Scalar Values?
- Example 2: How to Determine Mean and Variance of Continuous Uniform Distribution Corresponding to Two Arrays?
- Example 3: How to Determine Mean and Variance of Continuous Uniform Distribution Corresponding to Data Stored in Two Excel Files?
How to Find Mean and Variance of Discrete Uniform Distribution in MATLAB?
- Example 1: How to Determine Mean and Variance of Discrete Uniform Distribution Corresponding to Scalar Value?
- Example 2: How to Determine Mean and Variance of Discrete Uniform Distribution Corresponding to an Array?
- Example 3: How to Determine Mean and Variance of Discrete Uniform Distribution Corresponding to Data Stored in an Excel File?
What is Uniform Distribution?
The uniform distribution is a statistical technique. It describes every outcome has an equal occurring opportunity. This is also called rectangular distribution with a constant probability distribution function. This distribution has two types:
- Continuous uniform distribution.
- Discrete uniform distribution.
What is Continuous Uniform Distribution?
The continuous uniform distribution contains all continuous and infinite variables. Each outcome in this distribution has an equal occurring opportunity. It includes two parameters a and b. It has a constant probability distribution function lying between its bounding parameters a and b. Where a represents the lower-end point and b represents the upper-bound point. The standard continuous uniform distribution has a=0 and b=1. This distribution consists of the following statistics:
Where represents the mean and represents the variance of continuous uniform distribution.
What is Discrete Uniform Distribution?
The discrete uniform distribution contains all discrete and countable variables. Each outcome of this distribution has an equal occurring opportunity. This distribution has only one parameter N. The statistics such as mean and variance of discrete uniform distribution are given below:
Where represents the mean and represents the variance of the discrete uniform distribution.
What Are the Applications of Uniform Distribution?
The uniform distribution has many real-life applications across various fields such as:
- It is used in medical research for randomly assigning patients to different treatment groups.
- It is used to optimize and analyze the performance of querying systems like transportation networks and call centers.
- It is used in gaming and lottery to ensure that each outcome has an equal occurring opportunity.
- It is used in sports to measure the order of team pairings to ensure that each team has equal occurring opportunities.
- It is used in computers and networks for load balancing.
- It is used in random number generation algorithms.
- It is used in computer gaming as well as simulation.
How to Find Mean and Variance of Uniform Distribution in MATLAB?
As we know uniform distribution has two types continuous and discrete uniform distributions. These distributions have different parameters and formulas to find their statistics. So MATLAB provides us with two built-in functions unifstat() and unidstat(). These functions find the mean and variance of continuous as well as discrete uniform distributions respectively.
How to Find Mean and Variance of Continuous Uniform Distribution in MATLAB?
In MATLAB, the continuous uniform distribution’s mean and variance can be determined using the unifstat() function. This function accepts two mandatory inputs which are the lower and upper bounds of continuous uniform distribution and uses these inputs to calculate the mean and variance of this distribution.
Syntax
The unifstat() function follows the following syntax to find the mean and variance of continuous uniform distribution in MATLAB.
Here,
The function [M,V] = unifstat(A,B) is responsible for calculating mean M and variance V of the continuous uniform distribution corresponding to the lower-end points A and the upper-end points B using the above-given mean and variance formulas where A<B.
- If A and B are scalar values, this function considers them as constant vectors having the same size and calculates mean and variance for each corresponding point of A and B where the size of M and V will be the same as the size of A and B.
- If A and B are arrays, they must have the same size. This function calculates the mean and variance of the corresponding elements of A and B having the same size as A and B.
Example 1: How to Determine Mean and Variance of Continous Uniform Distribution Corresponding to Scalar Values?
In this MATLAB code, we initialize two scalar values A=7 and B=10 where A represents the lower-end point and B represents the upper-end point. After that, we use the unifstat() function to compute mean M and variance v of the continuous uniform distribution corresponding to A and B.
B = 10;
[M,v]=unifstat(A,B)
Example 2: How to Determine Mean and Variance of Continuous Uniform Distribution Corresponding to Two Arrays?
This example determines the mean and variance of the continuous uniform distribution corresponding to each element of given matrices A and B using the unifstat() function. Here, A represents the lower-end point and B represents the upper-end point.
B = magic(4);
[M,v]=unifstat(A,B)
Example 3: How to Determine Mean and Variance of Continuous Uniform Distribution Corresponding to Data Stored in Two Excel Files?
The below-given MATLAB code implements the unifstat() function to compute the mean M and variance v of the continuous uniform distribution corresponding to each element of the given Excel files A.xlsx and B.xlsx. To perform this task, first of all, it reads data from the Excel files using the readmatrix() function and transforms them into matrices A and B.
B = readmatrix("B.xlsx");
[M,v]=unifstat(A',B')
Click here to learn how to convert an Excel file into a matrix.
How to Find Mean and Variance of Discrete Uniform Distribution in MATLAB?
The discrete uniform distribution’s mean and variance can be computed in MATLAB using the unidstat() function. This function takes discrete uniform distribution parameter N as a mandatory argument and calculates the mean and variance of this distribution.
Syntax
The unidstat() function can be implemented in MATLAB through the below syntax to find the mean and variance of the discrete uniform distribution.
Here,
The function [M,V] = unidstat(N) is responsible for computing mean M and variance V of the discrete uniform distribution using the above-given formulas. This function considers 1 as a minimum value and N as a maximum value. Here N can be a scalar or an array.
- If N represents an array, this function calculates the mean and variance of each value of N and returns M and V in the form of an array having the same size as N.
Example 1: How to Determine Mean and Variance of Discrete Uniform Distribution Corresponding to Scalar Value?
This MATLAB code implements the unidstat() function to calculate the mean M and variance v of the discrete uniform distribution corresponding to the given scalar value A =7.
[M,v] = unidstat(A)
Example 2: How to Determine Mean and Variance of Discrete Uniform Distribution Corresponding to an Array?
In the below-given example, we determine the mean M and variance v of the discrete uniform distribution corresponding to each value of the given 4-by-4 matrix A using the unidstat() function.
[M,v] = unidstat(A)
Example 3: How to Determine Mean and Variance of Discrete Uniform Distribution Corresponding to Data Stored in an Excel File?
This example reads data from the given Excel file A.xlsx in the form of a matrix using the readmatrix() function. After that, it uses the unidstat() function to compute the mean M and variance v of the discrete uniform distribution for each value of the matrix A.
[M,v]=unidstat(A')
Conclusion
Uniform distribution includes all random variables that have an equal occurrence chance. There are 2 types of uniform distribution. One is continuous uniform distribution. This distribution has continuous and infinite random variables. These variables have an equal chance of occurrence. Another type of uniform distribution is the discrete uniform distribution. This distribution has discrete and countable random variables. These variables have an equal opportunity of occurrence. The uniform distribution has many real-life applications. Such as it is used in medical research, computer simulation, and gaming, sports, and computer and distributed networks.
Manually finding the statistics of continuous and discrete uniform distributions has become an impractical approach. Because of the accessibility of MATLAB’s built-in unifstat() and unidstat() functions. These functions compute the mean and variance of continuous and discrete uniform distributions efficiently. This guide presented the implementation of these two functions with the help of examples.