Skip to content
Snippets Groups Projects
Commit 05e18af1 authored by Mitchell Welch's avatar Mitchell Welch
Browse files

Adding another notebook

parent dce012ed
Branches master
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# The Lorenz Differential Equations
%% Cell type:markdown id: tags:
Before we start, we import some preliminary libraries. We will also import (below) the accompanying `lorenz.py` file, which contains the actual solver and plotting routine.
%% Cell type:code id: tags:
``` python
%matplotlib inline
from ipywidgets import interactive, fixed
```
%% Cell type:markdown id: tags:
We explore the Lorenz system of differential equations:
$$
\begin{aligned}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{aligned}
$$
Let's change (\\(\sigma\\), \\(\beta\\), \\(\rho\\)) with ipywidgets and examine the trajectories.
%% Cell type:code id: tags:
``` python
from lorenz import solve_lorenz
w=interactive(solve_lorenz,sigma=(0.0,50.0),rho=(0.0,50.0))
w
```
%% Cell type:markdown id: tags:
For the default set of parameters, we see the trajectories swirling around two points, called attractors.
%% Cell type:markdown id: tags:
The object returned by `interactive` is a `Widget` object and it has attributes that contain the current result and arguments:
%% Cell type:code id: tags:
``` python
t, x_t = w.result
```
%% Cell type:code id: tags:
``` python
w.kwargs
```
%% Cell type:markdown id: tags:
After interacting with the system, we can take the result and perform further computations. In this case, we compute the average positions in \\(x\\), \\(y\\) and \\(z\\).
%% Cell type:code id: tags:
``` python
xyz_avg = x_t.mean(axis=1)
```
%% Cell type:code id: tags:
``` python
xyz_avg.shape
```
%% Cell type:markdown id: tags:
Creating histograms of the average positions (across different trajectories) show that, on average, the trajectories swirl about the attractors.
%% Cell type:code id: tags:
``` python
from matplotlib import pyplot as plt
```
%% Cell type:code id: tags:
``` python
plt.hist(xyz_avg[:,0])
plt.title('Average $x(t)$');
```
%% Cell type:code id: tags:
``` python
plt.hist(xyz_avg[:,1])
plt.title('Average $y(t)$');
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment