# Interact Exercise 6

## Imports

Put the standard imports for Matplotlib, Numpy and the IPython widgets in the following cell.


```python
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
```


```python
from IPython.display import Image
from IPython.html.widgets import interact, interactive, fixed
```

## Exploring the Fermi distribution

In quantum statistics, the [Fermi-Dirac](http://en.wikipedia.org/wiki/Fermi%E2%80%93Dirac_statistics) distribution is related to the probability that a particle will be in a quantum state with energy $\epsilon$. The equation for the distribution $F(\epsilon)$ is:


```python
Image('fermidist.png')
```

In this equation:

* $\epsilon$ is the single particle energy.
* $\mu$ is the chemical potential, which is related to the total number of particles.
* $k$ is the Boltzmann constant.
* $T$ is the temperature in Kelvin.

In the cell below, typeset this equation using LaTeX:

\begin{align}
F(\epsilon) = \frac{1}{e^{(\epsilon-\mu)/kt} + 1}
\end{align}

Define a function `fermidist(energy, mu, kT)` that computes the distribution function for a given value of `energy`, chemical potential `mu` and temperature `kT`. Note here, `kT` is a single variable with units of energy. Make sure your function works with an array and don't use any `for` or `while` loops in your code.


```python
def fermidist(energy, mu, kT):
    """Compute the Fermi distribution at energy, mu and kT."""
    f = 1/(np.exp((energy-mu)/kT)+1)
    return f
```


```python
assert np.allclose(fermidist(0.5, 1.0, 10.0), 0.51249739648421033)
assert np.allclose(fermidist(np.linspace(0.0,1.0,10), 1.0, 10.0),
    np.array([ 0.52497919,  0.5222076 ,  0.51943465,  0.5166605 ,  0.51388532,
               0.51110928,  0.50833256,  0.50555533,  0.50277775,  0.5       ]))
```

Write a function `plot_fermidist(mu, kT)` that plots the Fermi distribution $F(\epsilon)$ as a function of $\epsilon$ as a line plot for the parameters `mu` and `kT`.

* Use enegies over the range $[0,10.0]$ and a suitable number of points.
* Choose an appropriate x and y limit for your visualization.
* Label your x and y axis and the overall visualization.
* Customize your plot in 3 other ways to make it effective and beautiful.


```python
def plot_fermidist(mu, kT):
    plt.figure(figsize=(9,6))
    plt.plot(np.linspace(0.0,10.0,100),fermidist(np.linspace(0.0,10.0,100), mu, kT),'r')
    plt.xlabel('Energy')
    plt.ylabel('Fermi Distribution')
    plt.title('Fermi Distribution as a function of Energy')
    plt.xlim(0.0, 10.0)
    plt.ylim(0.0, 1.0)
    plt.grid(True)
    plt.box(False)
```


```python
plot_fermidist(4.0, 1.0)
```


```python
assert True # leave this for grading the plot_fermidist function
```

Use `interact` with `plot_fermidist` to explore the distribution:

* For `mu` use a floating point slider over the range $[0.0,5.0]$.
* for `kT` use a floating point slider over the range $[0.1,10.0]$.


```python
interact(plot_fermidist, mu=(0.0,10.0),kT=(0.1,10.0));
```

Provide complete sentence answers to the following questions in the cell below:

* What happens when the temperature $kT$ is low?
* What happens when the temperature $kT$ is high?
* What is the effect of changing the chemical potential $\mu$?
* The number of particles in the system are related to the area under this curve. How does the chemical potential affect the number of particles.

Use LaTeX to typeset any mathematical symbols in your answer.

When $kT$ was low, the curve of $F$ became very steep. When $kT$ was high, the curve became much shallower. Changing the chemical potential $\mu$ shifts the graph to the right with an increase, and to the left with a decrease. A decrease in $\mu$ decreases the number of particles in the system and vice versa.

cd5ad556ddb11c54e7ac5cb13ec9436ca3b20a5e
ipynb
Jupyter Notebook
assignments/midterm/InteractEx06.ipynb
joshnsolomon/Josh-Solomon-PHYS-202-work
919bb26416af0e81ca9724d5991e041dbd79d164
MIT
assignments/midterm/InteractEx06.ipynb
joshnsolomon/Josh-Solomon-PHYS-202-work
919bb26416af0e81ca9724d5991e041dbd79d164
MIT
assignments/midterm/InteractEx06.ipynb
joshnsolomon/Josh-Solomon-PHYS-202-work
919bb26416af0e81ca9724d5991e041dbd79d164
MIT
Qwen/Qwen-72B
1. YES
2. YES