Uniform Distribution (Continuous) - MATLAB & Simulink (2024)

Uniform Distribution (Continuous)

Overview

The uniform distribution (also called the rectangular distribution) is a two-parameter family of curves that is notable because it has a constant probability distribution function (pdf) between its two bounding parameters. This distribution is appropriate for representing the distribution of round-off errors in values tabulated to a particular number of decimal places. The uniform distribution is used in random number generating techniques such as the inversion method.

Statistics and Machine Learning Toolbox™ offers several ways to work with the uniform distribution.

  • Create a probability distribution object UniformDistribution by specifying parameter values (makedist). Then, use object functions to evaluate the distribution, generate random numbers, and so on.

  • Use distribution-specific functions (unifcdf, unifpdf, unifinv, unifit, unifstat, unifrnd) with specified distribution parameters. The distribution-specific functions can accept parameters of multiple uniform distributions.

  • Use generic distribution functions (cdf, icdf, pdf, random) with a specified distribution name ('Uniform') and parameters.

Parameters

The uniform distribution uses the following parameters.

ParameterDescriptionSupport
aLower endpoint-∞ < a < b
bUpper endpoint a < b <

The standard uniform distribution has a = 0 and b = 1.

Parameter Estimation

The maximum likelihood estimates (MLEs) are the parameter estimates that maximize the likelihood function. The maximum likelihood estimators of a and b for the uniform distribution are the sample minimum and maximum, respectively.

To fit the uniform distribution to data and find parameter estimates, use unifit or mle.

Probability Density Function

The pdf of the uniform distribution is

f(x|a,b)={(1ba);axb0;otherwise.

The pdf is constant between a and b.

For an example, see Compute Continuous Uniform Distribution pdf.

Cumulative Distribution Function

The cumulative distribution function (cdf) of the uniform distribution is

F(x|a,b)={0;x<axaba;ax<b1;xb.

The result p is the probability that a single observation from a uniform distribution with parameters a and b falls in the interval [ax].

For an example, see Compute Continuous Uniform Distribution cdf.

Descriptive Statistics

The mean of the uniform distribution is μ=12(a+b).

The variance of the uniform distribution is σ2=112(ba)2.

Random Number Generation

You can use the standard uniform distribution to generate random numbers for any other continuous distribution by the inversion method. The inversion method relies on the principle that continuous cumulative distribution functions (cdfs) range uniformly over the open interval (0, 1). If u is a uniform random number on (0, 1), then x = F–1(u) generates a random number x from the continuous distribution with the specified cdf F.

For an example, see Generate Random Numbers Using Uniform Distribution Inversion.

Examples

Compute Continuous Uniform Distribution pdf

Open Live Script

Create three uniform distribution objects with different parameters.

pd1 = makedist('Uniform'); % Standard uniform distributionpd2 = makedist('Uniform','lower',-2,'upper',2); % Uniform distribution with a = -2 and b = 2pd3 = makedist('Uniform','lower',-2,'upper',1); % Uniform distribution with a = -2 and b = 1

Compute the pdfs for the three uniform distributions.

x = -3:.01:3;pdf1 = pdf(pd1,x);pdf2 = pdf(pd2,x);pdf3 = pdf(pd3,x);

Plot the pdfs on the same axis.

figure;plot(x,pdf1,'r','LineWidth',2); hold on;plot(x,pdf2,'k:','LineWidth',2);plot(x,pdf3,'b-.','LineWidth',2);legend({'a = 0, b = 1','a = -2, b = 2','a = -2, b = 1'},'Location','northwest');xlabel('Observation')ylabel('Probability Density')hold off;

Uniform Distribution (Continuous)- MATLAB & Simulink (1)

As the width of the interval (a,b) increases, the height of each pdf decreases.

Compute Continuous Uniform Distribution cdf

Open Live Script

Create three uniform distribution objects with different parameters.

pd1 = makedist('Uniform'); % Standard uniform distributionpd2 = makedist('Uniform','lower',-2,'upper',2); % Uniform distribution with a = -2 and b = 2pd3 = makedist('Uniform','lower',-2,'upper',1); % Uniform distribution with a = -2 and b = 1

Compute the cdfs for the three uniform distributions.

x = -3:.01:3;cdf1 = cdf(pd1,x);cdf2 = cdf(pd2,x);cdf3 = cdf(pd3,x);

Plot the cdfs on the same axis.

figure;plot(x,cdf1,'r','LineWidth',2); hold on;plot(x,cdf2,'k:','LineWidth',2);plot(x,cdf3,'b-.','LineWidth',2);legend({'a = 0, b = 1','a = -2, b = 2','a = -2, b = 1'},'Location','NW');xlabel('Observation')ylabel('Cumulative Probability')hold off;

Uniform Distribution (Continuous)- MATLAB & Simulink (2)

As the width of the interval (a,b) increases, the slope of each cdf decreases.

Related Distributions

  • Beta Distribution — The beta distribution is a two-parameter continuous distribution that has parameters a (first shape parameter) and b (second shape parameter). The standard uniform distribution is equal to the beta distribution with unit parameters.

  • Triangular Distribution — The triangular distribution is a three-parameter continuous distribution that has parameters a (lower limit), b (peak), and c (upper limit). The sum of two random variables with a standard uniform distribution has a triangular distribution with a = 0, b = 1, and c = 0.

References

[1] Abramowitz, Milton, and Irene A. Stegun, eds. Handbook of Mathematical Functions: With Formulas, Graphs, and Mathematical Tables. 9. Dover print.; [Nachdr. der Ausg. von 1972]. Dover Books on Mathematics. New York, NY: Dover Publ, 2013.

[2] Devroye, Luc. Non-Uniform Random Variate Generation. New York, NY: Springer New York, 1986. https://doi.org/10.1007/978-1-4613-8643-8

[3] Evans, Merran, Nicholas Hastings, and Brian Peaco*ck. Statistical Distributions. 2nd ed. New York: J. Wiley, 1993.

See Also

UniformDistribution | unifcdf | unifpdf | unifinv | unifit | unifstat | unifrnd | makedist | fitdist

Related Topics

  • Generate Random Numbers Using Uniform Distribution Inversion
  • Working with Probability Distributions
  • Supported Distributions

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.

Uniform Distribution (Continuous)- MATLAB & Simulink (3)

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:

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
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Uniform Distribution (Continuous)
- MATLAB & Simulink (2024)

FAQs

How to generate a uniform distribution in Matlab? ›

Uniform Distribution (Continuous)
  1. Create a probability distribution object UniformDistribution by specifying parameter values. ...
  2. Use distribution-specific functions with specified distribution parameters. ...
  3. Use the generic distribution functions with the specified distribution name "Uniform" and corresponding parameters.

How do you solve a continuous uniform distribution? ›

The general formula for the probability density function (pdf) for the uniform distribution is: f(x) = 1/ (B-A) for A≤ x ≤B. “A” is the location parameter: The location parameter tells you where the center of the graph is. “B” is the scale parameter: The scale parameter stretches the graph out on the horizontal axis.

How to plot CDF of uniform distribution in Matlab? ›

Compute Continuous Uniform Distribution cdf

Compute the cdfs for the three uniform distributions. x = -3:. 01:3; cdf1 = cdf(pd1,x); cdf2 = cdf(pd2,x); cdf3 = cdf(pd3,x); Plot the cdfs on the same axis.

What is a continuous probability distribution in Matlab? ›

A continuous probability distribution is one where the random variable can assume any value. Statistics and Machine Learning Toolbox™ offers several ways to work with continuous probability distributions, including probability distribution objects, command line functions, and interactive apps.

How do you make a uniform distribution? ›

The notation for the uniform distribution is: X ~ U(a, b) where a = the lowest value of x and b = the highest value of x. The probability density function is f(x) = 1b−a for a ≤ x ≤ b.

What is the difference between a Gaussian normal distribution and a uniform distribution? ›

Key Takeaways

In a continuous uniform distribution, outcomes are continuous and infinite. In a normal distribution, data around the mean occur more frequently than occurrences farther from it. Uniform distributions can be plotted on charts or graphs.

What is an example of a continuous uniform distribution in real life? ›

Examples of Uniform Distribution

For example, if you stand on a street corner and start to randomly hand a $100 bill to any lucky person who walks by, then every passerby would have an equal chance of being handed the money.

What is the difference between discrete and continuous uniform distribution? ›

Uniform distributions are probability distributions with equally likely outcomes. In a discrete uniform distribution, outcomes are discrete and have the same probability. In a continuous uniform distribution, outcomes are continuous and infinite. In a normal distribution, data around the mean occur more frequently.

What is the mean formula for continuous uniform distribution? ›

A "uniform distribution" means all possible outcomes in the range have equal probability of occurring. These two pieces build to create a continuous uniform distribution. The mean of a continuous uniform distribution between bounds a and b has a simple formula: μ = a + b 2 .

What is the PDF of uniform distribution in Matlab? ›

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

What is the Unifcdf function in Matlab? ›

Description. p = unifcdf( x , a , b ) returns the continuous uniform cumulative distribution function (cdf) at each value in x using the corresponding lower endpoint a and upper endpoint b .

What is CDF in uniform distribution? ›

The cumulative distribution function of a uniform random variable is: F ( x ) = x − a b − a. for two constants and such that a < x < b .

What is continuous uniform probability distribution? ›

The uniform distribution (continuous) is one of the simplest probability distributions in statistics. It is a continuous distribution, this means that it takes values within a specified range, e.g. between 0 and 1.

What is the CDF of continuous probability distributions? ›

CDF of a Continuous Random Variable

Let X be a continuous random variable with pdf f(x) . Then the cumulative distribution function F(x) can be expressed by F(x)=x∫−∞f(t)dt. F ( x ) = ∫ − ∞ x f ( t ) d t .

How do you generate a uniform random variable in Matlab? ›

r = unifrnd( a , b , sz1,...,szN ) generates an array of uniform random numbers, where sz1,...,szN indicates the size of each dimension. r = unifrnd( a , b , sz ) generates an array of uniform random numbers, where the size vector sz specifies size(r) .

How do you create a custom distribution in Matlab? ›

Define Custom Distribution

To define a custom distribution using the app, select File > Define Custom Distributions. A file template opens in the MATLAB Editor. You then edit this file so that it creates a probability object for the distribution you want.

How to generate uniform random numbers? ›

The main idea here is we take an integer, square it, and then use the middle part of that integer as our next random integer, repeating the process as many times as we need. To generate the Uniform(0,1) random variable, we would divide each generated integer by the appropriate power of ten.

How to create a diagonal matrix in Matlab? ›

D = diag( v ) returns a square diagonal matrix with the elements of vector v on the main diagonal. D = diag( v , k ) places the elements of vector v on the k th diagonal. k=0 represents the main diagonal, k>0 is above the main diagonal, and k<0 is below the main diagonal.

Top Articles
Latest Posts
Article information

Author: Annamae Dooley

Last Updated:

Views: 5895

Rating: 4.4 / 5 (45 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Annamae Dooley

Birthday: 2001-07-26

Address: 9687 Tambra Meadow, Bradleyhaven, TN 53219

Phone: +9316045904039

Job: Future Coordinator

Hobby: Archery, Couponing, Poi, Kite flying, Knitting, Rappelling, Baseball

Introduction: My name is Annamae Dooley, I am a witty, quaint, lovely, clever, rich, sparkling, powerful person who loves writing and wants to share my knowledge and understanding with you.