# Project 1

The Lorenz equations show deterministic non-periodic behavior, or chaos.  One aspect of this behavior is the system's sensitive dependence on initial conditions, which has been termed "the butterfly effect" and has been discussed
and used in many books and movies.  The Lorenz equations are:

\begin{align}
   \frac{{\rm d}x(t)}{{\rm d}t} &= \sigma (y(t) -x(t)) \\
   \frac{{\rm d}y(t)}{{\rm d}t} &= x(t) (\rho - z(t)) - y(t) \\
   \frac{{\rm d}z(t)}{{\rm d}t} &= x(t)y(t) - \beta z(t)
\end{align}

where $\sigma, \rho$ and $\beta$ are constants, $x, y$, and $z$ are dependent variables and $t$ is time.  In this problem you will integrate the Lorenz equations in time for different values of $\rho$ and different initial conditions in order to see the butterfly effect for yourself.

1. Complete the Python class `Lorenz()` to integrate the Lorenz equations with different initial conditions.  The values of $\sigma$, $\beta$, and $\rho$ should be set as arguments to the class and the initial conditions vector to $[x_0, 1, 0]$ where $x_0$ is given as an argument to the class function `solve()` which should return the solution.
 
    **Hint**: Google `scipy.integrate.odeint`.  

2. Set $\sigma=10$, $\beta=8/3$, and $\rho =14$ and integrate the Lorenz equation twice, with $x_0 = 0$, and then with $x_0 = 1 \times 10^{-5}$.  Use subscript $1$ for the result when $x_0 = 0$ and subscript $2$ for the result when $x_0 = 1 \times 10^{-5}$ .  For this value of $\rho$, the behavior of the system is called a stable limit cycle.
 
   Using `matplotlib`, make three plots:

     a. $x_1(t)$ and $x_2(t)$ as a function of $t$ 
    
     b. the absolute value of the difference $x_1(t) - x_2(t)$ as a function of $t$

     c. $z_1$ as a function of $x_1$, which is called a phase plot

1. Repeat Steps 2 and 3 above with $\rho = 28$.  For the value of $\rho$, the behavior of the system is called a strange attractor.  The second plot of the absolute value of the difference of $x_1(t) - x_2(t)$ demonstrates the butterfly effect.

1. Complete the function `plot()` so that 2 and 3 above automatically (without any arguments) create the following plot.

   


```python
import numpy as np
import scipy.integrate

import matplotlib
import matplotlib.pyplot as plt

class Lorenz(object):
    
    def __init__(self, sigma, beta, rho):
        
        self.sigma = sigma
        self.beta = beta
        self.rho = rho
        
        self.t = np.linspace(0,100,num=10000)

    
    def solve(self, x0):
       
        return
    
    
    def plot(self, figname=None):
        
        
        if figname is not None:
            plt.savefig(figname, bbox_inches='tight')
```


```python
#%matplotlib inline
#l = Lorenz(0,0,0)
#l.plot('lorenz_gold.png')
```

492d7bbab44705cab7ce169d6ce06fec700ecfad
ipynb
Jupyter Notebook
project1.ipynb
PGE383-HPC-Students/project1
279f11ade37e44fcc46ee01827d560128da0aee3
MIT
project1.ipynb
PGE383-HPC-Students/project1
279f11ade37e44fcc46ee01827d560128da0aee3
MIT
project1.ipynb
PGE383-HPC-Students/project1
279f11ade37e44fcc46ee01827d560128da0aee3
MIT
Qwen/Qwen-72B
1. YES
2. YES