Normal Distribution - MATLAB & Simulink (2024)

Normal Distribution

Overview

The normal distribution, sometimes called the Gaussian distribution, is a two-parameter family of curves. The usual justification for using the normal distribution for modeling is the Central Limit theorem, which states (roughly) that the sum of independent samples from any distribution with finite mean and variance converges to the normal distribution as the sample size goes to infinity.

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

  • Create a probability distribution object NormalDistribution by fitting a probability distribution to sample data (fitdist) or by specifying parameter values (makedist). Then, use object functions to evaluate the distribution, generate random numbers, and so on.

  • Work with the normal distribution interactively by using the Distribution Fitter app. You can export an object from the app and use the object functions.

  • Use distribution-specific functions (normcdf, normpdf, norminv, normlike, normstat, normfit, normrnd) with specified distribution parameters. The distribution-specific functions can accept parameters of multiple normal distributions.

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

Parameters

The normal distribution uses these parameters.

ParameterDescriptionSupport
mu (μ)Mean<μ<
sigma (σ)Standard deviationσ0

The standard normal distribution has zero mean and unit standard deviation. If z is standard normal, then σz + µ is also normal with mean µ and standard deviation σ. Conversely, if x is normal with mean µ and standard deviation σ, then z = (xµ)/σ is standard normal.

Parameter Estimation

The maximum likelihood estimates (MLEs) are the parameter estimates that maximize the likelihood function. The maximum likelihood estimators of μ and σ2 for the normal distribution, respectively, are

x¯=i=1nxin

and

sMLE2=1ni=1n(xix¯)2.

x¯ is the sample mean for samples x1, x2, …, xn. The sample mean is an unbiased estimator of the parameter μ. However, s2MLE is a biased estimator of the parameter σ2, meaning that its expected value does not equal the parameter.

The minimum variance unbiased estimator (MVUE) is commonly used to estimate the parameters of the normal distribution. The MVUE is the estimator that has the minimum variance of all unbiased estimators of a parameter. The MVUEs of the parameters μ and σ2 for the normal distribution are the sample mean and sample variance s2, respectively.

s2=1n1i=1n(xix¯)2

To fit the normal distribution to data and find the parameter estimates, use normfit, fitdist, or mle.

  • For uncensored data, normfit and fitdist find the unbiased estimates, and mle finds the maximum likelihood estimates.

  • For censored data, normfit, fitdist, and mle find the maximum likelihood estimates.

Unlike normfit and mle, which return parameter estimates, fitdist returns the fitted probability distribution object NormalDistribution. The object properties mu and sigma store the parameter estimates.

For an example, see Fit Normal Distribution Object.

Probability Density Function

The normal probability density function (pdf) is

y=f(x|μ,σ)=1σ2πe(xμ)22σ2,forx.

The likelihood function is the pdf viewed as a function of the parameters. The maximum likelihood estimates (MLEs) are the parameter estimates that maximize the likelihood function for fixed values of x.

For an example, see Compute and Plot the Normal Distribution pdf.

Cumulative Distribution Function

The normal cumulative distribution function (cdf) is

p=F(x|μ,σ)=1σ2πxe(tμ)22σ2dt,forx.

p is the probability that a single observation from a normal distribution with parameters μ and σ falls in the interval (-∞,x].

The standard normal cumulative distribution function Φ(x) is functionally related to the error function erf.

Φ(x)=12(1erf(x2))

where

erf(x)=2π0xedt2t=2Φ(2x)1.

For an example, see Plot Standard Normal Distribution cdf

Examples

Fit Normal Distribution Object

Open Live Script

Load the sample data and create a vector containing the first column of student exam grade data.

load examgradesx = grades(:,1);

Create a normal distribution object by fitting it to the data.

pd = fitdist(x,'Normal')
pd = NormalDistribution Normal distribution mu = 75.0083 [73.4321, 76.5846] sigma = 8.7202 [7.7391, 9.98843]

The intervals next to the parameter estimates are the 95% confidence intervals for the distribution parameters.

Estimate Parameters

Open Live Script

Estimate normal distribution parameters (mean and standard deviation) by using the normfit function.

Load the sample data and create a vector containing the first column of student exam grade data.

load examgradesx = grades(:,1);

Find the parameter estimates and the 95% confidence intervals.

mu = 75.0083
s = 8.7202
muci = 2×1 73.4321 76.5846
sci = 2×1 7.7391 9.9884

The normfit function returns the minimum variance unbiased estimator (MVUE) for μ, the square root of the MVUE for σ2, and 95% confidence intervals for μ and σ.

Note that the square of s is the MVUE of the variance.

s^2
ans = 76.0419

Compute and Plot the Normal Distribution pdf

Open Live Script

Compute the pdf of a standard normal distribution, with parameters μ equal to 0 and σ equal to 1.

x = [-3:.1:3];y = normpdf(x,0,1);

Plot the pdf.

plot(x,y)

Normal Distribution- MATLAB & Simulink (1)

Plot Standard Normal Distribution cdf

Open Live Script

Create a standard normal distribution object.

pd = makedist('Normal')
pd = NormalDistribution Normal distribution mu = 0 sigma = 1

Specify the x values and compute the cdf.

x = -3:.1:3;p = cdf(pd,x);

Plot the cdf of the standard normal distribution.

plot(x,p)

Normal Distribution- MATLAB & Simulink (2)

Compare Gamma and Normal Distribution pdfs

Open Live Script

The gamma distribution has the shape parameter a and the scale parameter b. For a large a, the gamma distribution closely approximates the normal distribution with mean μ=ab and variance σ2=ab2.

Compute the pdf of a gamma distribution with parameters a = 100 and b = 5.

a = 100;b = 5;x = 250:750;y_gam = gampdf(x,a,b);

For comparison, compute the mean, standard deviation, and pdf of the normal distribution that gamma approximates.

mu = a*b
sigma = sqrt(a*b^2)
sigma = 50
y_norm = normpdf(x,mu,sigma);

Plot the pdfs of the gamma distribution and the normal distribution on the same figure.

plot(x,y_gam,'-',x,y_norm,'-.')title('Gamma and Normal pdfs')xlabel('Observation')ylabel('Probability Density')legend('Gamma Distribution','Normal Distribution')

Normal Distribution- MATLAB & Simulink (3)

The pdf of the normal distribution approximates the pdf of the gamma distribution.

Relationship Between Normal and Lognormal Distributions

Open Live Script

If X follows the lognormal distribution with parameters µ and σ, then log(X) follows the normal distribution with mean µ and standard deviation σ. Use distribution objects to inspect the relationship between normal and lognormal distributions.

Create a lognormal distribution object by specifying the parameter values.

pd = makedist('Lognormal','mu',5,'sigma',2)
pd = LognormalDistribution Lognormal distribution mu = 5 sigma = 2

Compute the mean of the lognormal distribution.

mean(pd)
ans = 1.0966e+03

The mean of the lognormal distribution is not equal to the mu parameter. The mean of the logarithmic values is equal to mu. Confirm this relationship by generating random numbers.

Generate random numbers from the lognormal distribution and compute their log values.

rng('default'); % For reproducibilityx = random(pd,10000,1);logx = log(x);

Compute the mean of the logarithmic values.

m = mean(logx)
m = 5.0033

The mean of the log of x is close to the mu parameter of x, because x has a lognormal distribution.

Construct a histogram of logx with a normal distribution fit.

histfit(logx)

Normal Distribution- MATLAB & Simulink (4)

The plot shows that the log values of x are normally distributed.

histfit uses fitdist to fit a distribution to data. Use fitdist to obtain parameters used in fitting.

pd_normal = fitdist(logx,'Normal')
pd_normal = NormalDistribution Normal distribution mu = 5.00332 [4.96445, 5.04219] sigma = 1.98296 [1.95585, 2.01083]

The estimated normal distribution parameters are close to the lognormal distribution parameters 5 and 2.

Compare Student's t and Normal Distribution pdfs

Open Live Script

The Student’s t distribution is a family of curves depending on a single parameter ν (the degrees of freedom). As the degrees of freedom ν approach infinity, the t distribution approaches the standard normal distribution.

Compute the pdfs for the Student's t distribution with the parameter nu = 5 and the Student's t distribution with the parameter nu = 15.

x = [-5:0.1:5];y1 = tpdf(x,5);y2 = tpdf(x,15);

Compute the pdf for a standard normal distribution.

z = normpdf(x,0,1);

Plot the Student's t pdfs and the standard normal pdf on the same figure.

plot(x,y1,'-.',x,y2,'--',x,z,'-')legend('Student''s t Distribution with \nu=5', ... 'Student''s t Distribution with \nu=15', ... 'Standard Normal Distribution','Location','best')xlabel('Observation')ylabel('Probability Density')title('Student''s t and Standard Normal pdfs')

Normal Distribution- MATLAB & Simulink (5)

The standard normal pdf has shorter tails than the Student's t pdfs.

Related Distributions

  • Binomial Distribution — The binomial distribution models the total number of successes in n repeated trials with the probability of success p. As n increases, the binomial distribution can be approximated by a normal distribution with µ = np and σ2 = np(1–p). See Compare Binomial and Normal Distribution pdfs.

  • Birnbaum-Saunders Distribution — If x has a Birnbaum-Saunders distribution with parameters β and γ, then

    (xββx)γ

    has a standard normal distribution.

  • Chi-Square Distribution — The chi-square distribution is the distribution of the sum of squared, independent, standard normal random variables. If a set of n observations is normally distributed with variance σ2, and s2 is the sample variance, then (n–1)s2/σ2 has a chi-square distribution with n–1 degrees of freedom. The normfit function uses this relationship to calculate confidence intervals for the estimate of the normal parameter σ2 .

  • Extreme Value Distribution — The extreme value distribution is appropriate for modeling the smallest or largest value from a distribution whose tails decay exponentially fast, such as, the normal distribution.

  • Gamma Distribution — The gamma distribution has the shape parameter a and the scale parameter b. For a large a, the gamma distribution closely approximates the normal distribution with mean μ = ab and variance σ2 = ab2. The gamma distribution has density only for positive real numbers. See Compare Gamma and Normal Distribution pdfs.

  • Half-Normal Distribution — The half-normal distribution is a special case of the folded normal and truncated normal distributions. If a random variable Z has a standard normal distribution, then X=μ+σ|Z| has a half-normal distribution with parameters μ and σ.

  • Logistic Distribution — The logistic distribution is used for growth models and in logistic regression. It has longer tails and a higher kurtosis than the normal distribution.

  • Lognormal Distribution — If X follows the lognormal distribution with parameters µ and σ, then log(X) follows the normal distribution with mean µ and standard deviation σ. See Relationship Between Normal and Lognormal Distributions.

  • Multivariate Normal Distribution — The multivariate normal distribution is a generalization of the univariate normal to two or more variables. It is a distribution for random vectors of correlated variables, in which each element has a univariate normal distribution. In the simplest case, there is no correlation among variables, and elements of the vectors are independent, univariate normal random variables.

  • Poisson Distribution — The Poisson distribution is a one-parameter discrete distribution that takes nonnegative integer values. The parameter, λ, is both the mean and the variance of the distribution. As λ increase, the Poisson distribution can be approximated by a normal distribution with µ = λ and σ2 = λ.

  • Rayleigh Distribution — The Rayleigh distribution is a special case of the Weibull distribution with applications in communications theory. If the component velocities of a particle in the x and y directions are two independent normal random variables with zero means and equal variances, then the distance the particle travels per unit time follows the Rayleigh distribution.

  • Stable Distribution — The normal distribution is a special case of the stable distribution. The stable distribution with the first shape parameter α = 2 corresponds to the normal distribution.

    N(μ,σ2)=S(2,0,σ2,μ).

  • Student's t Distribution — The Student’s t distribution is a family of curves depending on a single parameter ν (the degrees of freedom). As the degrees of freedom ν goes to infinity, the t distribution approaches the standard normal distribution. See Compare Student's t and Normal Distribution pdfs.

    If x is a random sample of size n from a normal distribution with mean μ, then the statistic

    t=x¯μs/n

    where x¯ is the sample mean and s is the sample standard deviation, has the Student's t distribution with n–1 degrees of freedom.

  • t Location-Scale Distribution — The t location-scale distribution is useful for modeling data distributions with heavier tails (more prone to outliers) than the normal distribution. It approaches the normal distribution as the shape parameter ν approaches infinity.

References

[1] Abramowitz, M., and I. A. Stegun. Handbook of Mathematical Functions. New York: Dover, 1964.

[2] Evans, M., N. Hastings, and B. Peaco*ck. Statistical Distributions. 2nd ed. Hoboken, NJ: John Wiley & Sons, Inc., 1993.

[3] Lawless, J. F. Statistical Models and Methods for Lifetime Data. Hoboken, NJ: Wiley-Interscience, 1982.

[4] Marsaglia, G., and W. W. Tsang. “A Fast, Easily Implemented Method for Sampling from Decreasing or Symmetric Unimodal Density Functions.” SIAM Journal on Scientific and Statistical Computing. Vol. 5, Number 2, 1984, pp. 349–359.

[5] Meeker, W. Q., and L. A. Escobar. Statistical Methods for Reliability Data. Hoboken, NJ: John Wiley & Sons, Inc., 1998.

See Also

NormalDistribution | normcdf | normpdf | norminv | normlike | normstat | normfit | normrnd | erf

Related Topics

  • Working with Probability Distributions
  • Supported Distributions
  • Compare Multiple Distribution Fits
  • Multivariate 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.

Normal Distribution- MATLAB & Simulink (6)

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

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Normal Distribution
- MATLAB & Simulink (2024)

FAQs

How to check normal distribution in MATLAB? ›

Plot Standard Normal Distribution cdf

Specify the x values and compute the cdf. x = -3:. 1:3; p = cdf(pd,x); Plot the cdf of the standard normal distribution.

How to generate samples from a normal distribution in MATLAB? ›

X = randn returns a random scalar drawn from the standard normal distribution. X = randn( n ) returns an n -by- n matrix of normally distributed random numbers. X = randn( sz1,...,szN ) returns an sz1 -by-... -by- szN array of random numbers where sz1,...,szN indicate the size of each dimension.

Why does MATLAB say not enough input arguments? ›

"Not enough arguments" error is simply an indicative of the fact that you are calling some MATLAB/user-defined function with the wrong syntactical signature. You will need to pass correct number of inputs arguments to any function. Look closely at the exact error message you are recieving.

Why is normal distribution not a good model for financial data? ›

Normal distribution cannot be used to model stock prices because it has a negative side, and stock prices cannot fall below zero. Another similar use of the lognormal distribution is with the pricing of options.

How to know if a data is normally distributed? ›

In a normal distribution, data are symmetrically distributed with no skew. Most values cluster around a central region, with values tapering off as they go further away from the center. The measures of central tendency (mean, mode, and median) are exactly the same in a normal distribution.

How to check normalization in matlab? ›

N = normalize(___, method ) specifies a normalization method with any of the previous syntaxes. For example, normalize(A,"norm") normalizes the data in A by the Euclidean norm (2-norm). N = normalize(___, method , methodtype ) specifies the type of normalization for the given method.

How to generate standard normal distribution in matlab? ›

r = normrnd( mu , sigma ) generates a random number from the normal distribution with mean parameter mu and standard deviation parameter sigma . r = normrnd( mu , sigma , sz1,...,szN ) generates an array of normal random numbers, where sz1,...,szN indicates the size of each dimension.

What is the PDF of the normal distribution in matlab? ›

y = normpdf( x ) returns the probability density function (pdf) of the standard normal distribution, evaluated at the values in x . y = normpdf( x , mu ) returns the pdf of the normal distribution with mean mu and the unit standard deviation, evaluated at the values in x .

How do I make MATLAB more accurate? ›

By default, MATLAB® uses 16 digits of precision. For higher precision, use the vpa function in Symbolic Math Toolbox™. vpa provides variable precision which can be increased without limit.

What does too many arguments mean in MATLAB? ›

1) Passing a function more input arguments than it expected to receive, perhaps by passing a list of inputs rather than a vector of inputs, or have tried to obtain two outputs from a function that only returns one. 2) You have multiple functions with the same name.

How do I fix errors in MATLAB? ›

If you are unfamiliar with the problem, right-click the highlighted code. The first item in the context menu shows the suggested fix. Select the item to apply the fix. If multiple instances of a problem exist, MATLAB might offer to apply the suggested fix for all instances of the problem.

What are the limitations of the normal distribution? ›

Limitations of Normal Distribution

Real-world data often has skewness or kurtosis that deviates from that of a normal distribution. This means that the normal distribution may not accurately describe the behavior of real-world data, especially if it is skewed or has extreme values (outliers).

Why is normal distribution not good? ›

Although normal distribution is a statistical concept, its applications in finance can be limited because financial phenomena—such as expected stock-market returns—do not fall neatly within a normal distribution. Prices tend to follow more of a log-normal distribution, right-skewed and with fatter tails.

Why do we use normal distribution instead of T distribution? ›

You must use the t-distribution table when working problems when the population standard deviation (σ) is not known and the sample size is small (n<30). General Correct Rule: If σ is not known, then using t-distribution is correct. If σ is known, then using the normal distribution is correct.

How do you test for normal distribution? ›

To test your data analytically for normal distribution, there are several test procedures, the best known being the Kolmogorov-Smirnov test, the Shapiro-Wilk test, and the Anderson Darling test. In all of these tests, you are testing the null hypothesis that your data are normally distributed.

How do you check if a distribution is approximately normal? ›

The most common graphical tool for assessing normality is the Q-Q plot. In these plots, the observed data is plotted against the expected quantiles of a normal distribution. It takes practice to read these plots. In theory, sampled data from a normal distribution would fall along the dotted line.

How do you find the normal distribution? ›

z = (X – μ) / σ

where X is a normal random variable, μ is the mean of X, and σ is the standard deviation of X. You can also find the normal distribution formula here. In probability theory, the normal or Gaussian distribution is a very common continuous probability distribution.

How do you know if a variable has a normal distribution? ›

A variable that is normally distributed has a histogram (or "density function") that is bell-shaped, with only one peak, and is symmetric around the mean.

Top Articles
Latest Posts
Article information

Author: Rueben Jacobs

Last Updated:

Views: 5990

Rating: 4.7 / 5 (77 voted)

Reviews: 84% 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.