Matlab

# How to Use Poisson Distribution in MATLAB & Simulink

Probability distributions are statistical techniques that measure an event’s occurrences in a specified time or space interval. The probability distributions have two types; continuous and discrete. The types of continuous probability distribution are Normal and exponential distributions. While the types of discrete probability distribution are Poisson and Binomial distributions.

Today, we will discuss how to use Poisson distribution in MATLAB. So we are going to explore:

## What is Poisson Probability Distribution?

The Poisson distribution is a form of discrete probability distribution that provides the probability of the occurrence of an event for a certain number of times in the time or space interval. This distribution gives the probability of countable(discrete) outcomes. It has only one parameter that is denoted by Â and called lambda which represents the mean and variance of this distribution.

## Why do we Need the Poisson Probability Distribution?

The Poisson distribution has many applications in our daily life such as it is used:

• To predict text messages per hour.
• To predict the number of packets lost per minute in a network.
• To predict the number of website visitors per day.
• To predict COVID-19 cases per month.

## How to Use Poisson Distribution in MATLAB and Simulink?

The Poisson distribution can be implemented in MATLAB and Simulink to:

• Create a Poisson probability distribution object.
• Calculate a Poisson probability density function.
• Create random numbers Using the Poisson distribution.

## How to Use Poisson Distribution to Create Poisson Probability Distribution Object?

The Poisson probability distribution object includes a model description, parameters, and sample data. This object can be created in MATLAB using the built-in makedist() function.

## Syntax

The makedist() function follows a simple syntax to create a Poisson probability distribution object in MATLAB:

pd = makedist(â€˜poissonâ€™)
pd = makedist(â€˜poissonâ€™,â€™lambdaâ€™,Value)

Here,

The function pd=makedist(â€˜Poissonâ€™) is responsible for creating the Poisson probability distribution object. It uses the default lambda value which is 1. where lambda is a Poisson distribution parameter that represents the mean.

The function pd=makedist(â€˜Poissonâ€™, â€˜lambdaâ€™, Value) is responsible for creating a Poisson probability distribution object. Here, we can specify the lambda value of our own choice.

## Example 1: How to Create a Poisson Probability Distribution Object for the Default Lambda Value?

This example implements the pd = makedist(â€˜Poissonâ€™) function to create a Poisson distribution object for the default lambda value that is 1.

pd = makedist('Poisson')

## Example 2: How to Create a Poisson Probability Distribution Object for the Specified Lambda Value?

In this MATLAB code, we create a Poisson distribution object for the value lambda=10 using the function pd=makedist(â€˜Poissonâ€™, â€˜lambdaâ€™, Value).

pd = makedist('Poisson','lambda',10)

## How to Use Poisson Distribution to Calculate Poisson Probability Density Function?

The Poisson probability density function can be defined as:

Where,

• Î» represents the Poisson distribution parameter.
• X represents the happening of a random event.

The Poisson probability density function can be computed in MATLAB using the poisspdf() function. This function accepts x and lambda as mandatory parameters and returns a Poisson probability density function calculated by the above-given formula.

## Syntax

To calculate a Poisson probability density function, the poisspdf() can be implemented through the given syntax in MATLAB.

y = poisspdf(x,lambda)

Here,

The function y=poisspdf(x, lambda) is responsible for calculating the Poisson probability density function at each x value using the parameter lambda. Both parameters x and lambda can be scalar, vector, matrices, or multidirectional arrays having the same size. If one argument is scalar and the other is an array, this function expands the scalar to the constant array having the same size as the other argument.

## Example: How to Compute Poisson Density Function in MATLAB?

Consider a problem that in a classroom 3 students sit in a row on average. Calculate the Poisson probability density function for each student count from 1 to 5.

To solve this problem, the example below creates a vector containing the number of students from 1:5 and calculates the values of the Poisson probability density function at each value of the vector student using the poisspdf() function. After that, it uses the plot() function to plot the values of the Poisson probability density function against the number of students.

students = 1:5;
y = poisspdf(students,3)
plot(students,y)

## How to Use Poisson Distribution to Create Random Numbers?

The Poisson distribution allows us to create random numbers in MATLAB using the built-in poissrnd() function. This function accepts the Poisson distribution parameter Â lambda as a mandatory argument and creates a scalar or an array of random numbers using the Poisson distribution.

## Syntax

The poissrnd() uses the given syntaxes to create Poisson distribution random numbers in MATLAB.

r = poissrnd(lambda)
r = poissrnd(lambda,sz1,...,szN)

Here,

The function r=poissrnd(lambda) is responsible for creating a scalar random number from the Poisson distribution using the scalar value of lambda. In general, lambda can be a scalar, a vector, or a multi-directional array. This function generates an array of random numbers having the same size as the size of lambda.

The function r=poissrnd(lambda,sz1,…,szN) is responsible for creating an array of Poisson distribution random numbers. Hee, sz1,…,szN represent the array size and lambda is a scalar value.

## Example 1: How to Create a Scalar Random Number Using the Poisson Probability Distribution?

In this example, we use the poissrnd(lambda) function to create a scalar random number using lambda=10.

r = poissrnd(10)

## Example 2: How to Create an Array of Random Numbers Using the Poisson Probability Distribution?

The below-given MATLAB code creates an array of random numbers using the poissrnd(lambda,sz1,…,szN) function. Here, lambda is a scalar value that is 10 while the size of the array is 2-by-4-by-2.

A = poissrnd(10,2,4,2)

## Conclusion

Poisson probability distribution predicts the probability of the occurrence of an event for a certain number of times in a specified time or space interval. In MATLAB, it is used to create a Poisson probability distribution object and random numbers and calculate the value of the Poisson probability density function. This guide explored the uses of Poisson distribution in MATLAB with the help of practical examples.

### About the author

#### Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.