## Gaussian distribution – how to plot it in Matlab

In statistics and probability theory, the Gaussian distribution is a continuous distribution that gives a good description of data that cluster around a mean. The graph or plot of the associated probability density has a peak at the mean, and is known as the Gaussian function or bell curve. The Probability Density Function (PDF) in this case can be defined as: |

where

The formula above can me coded in Matlab easily, like this:

function f = gauss_distribution(x, mu, s)

p1 = -.5 * ((x - mu)/s) .^ 2;

p2 = (s * sqrt(2*pi));

f = exp(p1) ./ p2;

Now, let’s use it in an example.

We produce 500 random numbers between -100 and 100, with mean m = 0 and standard deviation s = 30. The code is:

a = -100; b = 100;

x = a + (b-a) * rand(1, 500);

m = (a + b)/2;

s = 30;

Then, we plot this information using our bell curve:

f = gauss_distribution(x, m, s);

plot(x,f,'.')

grid on

title('Bell Curve')

xlabel('Randomly produced numbers')

ylabel('Gauss Distribution')

The produced shape is:

An important property of this bell-shaped curve is that the values less than one standard deviation from the mean (between green lines below) represent approximately 68.2% of the area under the curve, while two standard deviations from the mean (between red lines below) take about 95.4%, and three standard deviations account for about 99.7% of the area.

From 'Gaussian distribution' to home

From 'Gaussian distribution' to Matlab 2D plots

Probability and Statistics

## how to plot a gaussian 1D in matlab

Fully parameterized gaussian function (no toolboxes needed)

If you don't have the Fuzzy Logic toolbox (and therefore do not have access to gaussmf), here's a simple anonymous function to create a paramaterized gaussian curve.

gaus = @(x,mu,sig,amp,vo)amp*exp(-(((x-mu).^2)/(2*sig.^2)))+vo;

- x is an array of x-values.
- mu is the mean
- sig is the standard deviation
- amp is the (positive or negative)
- vo is the vertical offset from baseline (positive or negative)

To add noise along the y-axis of the guassian,

y = gaus(___);

yh = y + randn(size(y))*amp*.10;

Demo

x = linspace(-5,25,100);

mu = 10;

sig = 5;

amp = 9;

vo = -5;

y = gaus(x,mu,sig,amp,vo);

plot(x, y, 'b-', 'LineWidth',3)

yh = y + randn(size(y))*amp*.10;

hold on

plot(x, yh, 'ro','markersize', 4)

grid on

title(sprintf('Guassian with \\mu=%.1f \\sigma=%.1f amp=%.1f vo=%.1f', ...

mu, sig, amp, vo))

Comparison with gaussmf()

x = linspace(-15,10,100);

mu = -5.8;

sig = 2.5;

amp = 1;

vo = 0;

y = gaus(x,mu,sig,amp,vo);

plot(x, y, 'b-', 'LineWidth',3, 'DisplayName','Custom function')

y2 = gaussmf(x,[sig,mu]);

hold on

plot(x, y2, 'r--', 'LineWidth',4, 'DisplayName','gaussmf()')

grid on

title(sprintf('Guassian with \\mu=%.1f \\sigma=%.1f amp=%.1f vo=%.1f', ...

mu, sig, amp, vo))

legend()

## Select a Web Site

### 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 by fitting a probability distribution to sample data () or by specifying parameter values (). 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 (, , , , , , ) with specified distribution parameters. The distribution-specific functions can accept parameters of multiple normal distributions.

Use generic distribution functions (, , , ) with a specified distribution name () and parameters.

### Parameters

The normal distribution uses these parameters.

Parameter | Description | Support |
---|---|---|

(μ) | Mean | |

(σ) | Standard deviation |

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

and

is the sample mean for samples *x*_{1}, *x*_{2}, …, *x*_{n}. The sample mean is an unbiased estimator of the parameter *μ*. However, *s*^{2}_{MLE} 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 *x̄* and sample variance *s*^{2}, respectively.

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

For uncensored data, and find the unbiased estimates, and finds the maximum likelihood estimates.

For censored data, , , and find the maximum likelihood estimates.

Unlike and , which return parameter estimates, returns the fitted probability distribution object . The object properties and store the parameter estimates.

For an example, see Fit Normal Distribution Object.

### Probability Density Function

The normal probability density function (pdf) is

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 .

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

### Cumulative Distribution Function

The normal cumulative distribution function (cdf) is

*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 .

where

For an example, see Plot Standard Normal Distribution cdf

### Examples

#### Fit Normal Distribution Object

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

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

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

#### Compute and Plot the Normal Distribution pdf

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

Plot the pdf.

#### Plot Standard Normal Distribution cdf

Create a standard normal distribution object.

Specify the values and compute the cdf.

Plot the cdf of the standard normal distribution.

#### Compare Gamma and Normal Distribution pdfs

The gamma distribution has the shape parameter and the scale parameter . For a large , the gamma distribution closely approximates the normal distribution with mean and variance .

Compute the pdf of a gamma distribution with parameters and .

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

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

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

#### Relationship Between Normal and Lognormal Distributions

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.

Compute the mean of the lognormal distribution.

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

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

Compute the mean of the logarithmic values.

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

Construct a histogram of with a normal distribution fit.

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

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

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

#### Compare Student's and Normal Distribution pdfs

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 and the Student's *t* distribution with the parameter .

Compute the pdf for a standard normal distribution.

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

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*µ*=*n**p*and*σ*^{2}=*n**p*(1–*p*). See Compare Binomial and Normal Distribution pdfs.Birnbaum-Saunders Distribution — If

*x*has a Birnbaum-Saunders distribution with parameters*β*and*γ*, thenhas 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*s*^{2}is the sample variance, then (*n*–1)*s*^{2}/*σ*^{2 }has a chi-square distribution with*n*–1 degrees of freedom. The 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*μ*=*a**b*and variance*σ*^{2}=*a**b*^{2}. 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 has a standard normal distribution, then 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.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 statisticwhere 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. Peacock. *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

| | | | | | | |

### Related Topics

You have a modified version of this example. Do you want to open this example with your edits?

## Select a Web Site

### Gaussian Models

### About Gaussian Models

The Gaussian model fits peaks, and is given by

where *a* is the amplitude, *b* is the centroid (location), *c* is related to the peak width, *n* is the number of peaks to fit, and 1 ≤ *n* ≤ 8.

Gaussian peaks are encountered in many areas of science and engineering. For example, Gaussian peaks can describe line emission spectra and chemical concentration assays.

### Fit Gaussian Models Interactively

Open the Curve Fitting app by entering . Alternatively, click Curve Fitting on the Apps tab.

In the Curve Fitting app, select curve data (

**X data**and**Y data**, or just**Y data**against index).Curve Fitting app creates the default curve fit, .

Change the model type from to .

You can specify the following options:

Choose the number of terms: to .

Look in the

**Results**pane to see the model terms, the values of the coefficients, and the goodness-of-fit statistics.(Optional) Click

**Fit Options**to specify coefficient starting values and constraint bounds, or change algorithm settings.The toolbox calculates optimized start points for Gaussian models, based on the current data set. You can override the start points and specify your own values in the Fit Options dialog box.

Gaussians have the width parameter constrained with a lower bound of . The default lower bounds for most library models are , which indicates that the coefficients are unconstrained.

For more information on the settings, see Specifying Fit Options and Optimized Starting Points.

### Fit Gaussian Models Using the fit Function

This example shows how to use the function to fit a Gaussian model to data.

The Gaussian library model is an input argument to the and functions. Specify the model type followed by the number of terms, e.g., through .

**Fit a Two-Term Gaussian Model**

Load some data and fit a two-term Gaussian model.

### See Also

| |

### Related Topics

You have a modified version of this example. Do you want to open this example with your edits?

## Matlab gaussian curve

He lies down on his back. What a body he has. Just perfect, pumped up, dark skinned, covered in tattoos.

Gaussian Curve - Clouds (Full Album)We should wash her with cool water, and take her out into the garden, breathe so that she regains consciousness, otherwise she is not even able to suck in this. Form.remarked Toha. Going out into the garden, we put Vera on a bench near the house and lit a cigarette.

### You will also like:

- Ice age fanfic
- Craft bag organizer
- Muncie childrens museum
- Kardon bluetooth speaker
- Wyndham rome ny
- Icd 10 osteoarthritis
- Gmc cadillac reno

Coming out of the shower, I came across Marina sitting in an armchair. She insolently looked at me and smoked a cigarette. Well, that the mischievous woman came to her senses.

**1668**1669 1670