# Introduction to the exponential distribution


```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
```

In queuing systems it is typically assumed that 

1. customers arrive at random
2. service time varies randomly.

The notion of *random* is closely associated with the **exponential distribution** (note this sometimes called the *negative* exponential distribution).  Its density function is given by (1).

\begin{equation}
f(t) = \lambda e^{-\lambda t}
\tag{1}
\end{equation}

where 
* $1/\lambda$ is the mean time between events.  
* $\lambda$ is the rate at which events occur (the expected no. of events per time unit)

To put it another way $f(t)$ represents the probability of an event occuring in the next t time units.

## Illustration: $\lambda = 1.0$

The chart below plot $f(t)$ for $\lambda = 1.0$.  It can be observed that the most likely times are the small values close to zero.  The longer the time the less likely it is to occur.  In other words, exponentially distributed times are most likely to be small and below the mean, but there still will be the occational long time.


```python
LAMBDA = 1.0
```


```python
#create 100 equally spaced time points between 0 and 5
t = np.linspace(0, 5, 100)
```


```python
#calculate f_t
f_t = LAMBDA * np.power(np.e, -LAMBDA * t)
```


```python
#plot
ax = pd.DataFrame(f_t, index=t).plot(figsize=(9, 6))
ax.legend(['$\lambda = 1.0$']);
ax.figure.savefig('exponential_1.png', bbox_inches='tight', dpi=300)
```

# Varying $\lambda$ changes the shape of the distribution.

The area under each density curve must equal 1.0.  This has consequences for the shape of the distribution as $\lambda$ varies in size.
The code below plots $f(t)$ while varying the parameter $\lambda = 1.0, 2.0, 3.0$.  We observe the following behaviour:

* A larger value of $\lambda$ leads to a more rapid decrease an asymptotic decrease to zero.


```python
fig, ax = plt.subplots(1, 1, figsize=(9, 6))

labels = []
for _lambda in range(1, 4):
    f_t = _lambda * np.power(np.e, -_lambda * t)
    ax.plot(pd.DataFrame(f_t, index=t))
    labels.append(f'$\lambda = {float(_lambda)}$')

ax.set_xlabel('t')
ax.set_ylabel('f(t)')
ax.legend(labels);
fig.savefig('exponential.png', bbox_inches='tight', dpi=300)
```


```python

```

1e8f3800502e82e7ccd3801b5c6b997114910f5c
ipynb
Jupyter Notebook
arrival_and_service_patterns.ipynb
TomMonks/jackson-network
bbb6fce334803b771fa57cc055fe06c5e93e3cdb
MIT
arrival_and_service_patterns.ipynb
TomMonks/jackson-network
bbb6fce334803b771fa57cc055fe06c5e93e3cdb
MIT
arrival_and_service_patterns.ipynb
TomMonks/jackson-network
bbb6fce334803b771fa57cc055fe06c5e93e3cdb
MIT
Qwen/Qwen-72B
1. YES
2. YES