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)
Top Articles
Latest Posts
Article information

Author: Rueben Jacobs

Last Updated:

Views: 6273

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Rueben Jacobs

Birthday: 1999-03-14

Address: 951 Caterina Walk, Schambergerside, CA 67667-0896

Phone: +6881806848632

Job: Internal Education Planner

Hobby: Candle making, Cabaret, Poi, Gambling, Rock climbing, Wood carving, Computer programming

Introduction: My name is Rueben Jacobs, I am a cooperative, beautiful, kind, comfortable, glamorous, open, magnificent person who loves writing and wants to share my knowledge and understanding with you.