Dynamical Systems with Theano
We can solve systems of differential equations using numerical methods. As an example, the equations for the Lorents Attractor:
These written (with more detail in LorentzAttractor.py):
def f(X):
X_ = T.zeros_like(X)
X_ = T.set_subtensor(X_[0], sigma * (X[1] - X[0]))
X_ = T.set_subtensor(X_[1], X[0] * (rho - X[2]) - X[1])
X_ = T.set_subtensor(X_[2], X[0] * X[1] - beta * X[2])
return X_
We can obtain a better estimate numerical estimate with RK4:
def step(X):
k1 = h * f(X)
k2 = h * f(X + 0.5 * k1)
k3 = h * f(X + 0.5 * k2)
k4 = h * f(X + k3)
X_ = X + (1.0 / 6.0) * k1 + (1.0 / 3.0) * k2 + (1.0 / 3.0) * k3 + (1.0 / 6.0) * k4
return X_
And we can iteratively solve to find the state of the system.
The equations for the pendulum angles are given by:
And the momentum:
We can use Runge-Kutta to solve these equations to produce:
For each different starting position we time plot how long it takes for the pendulum to flip, producing a fractal pattern.
The system of equations given by:
For the standard Mandelbrot set, we use the equations above, however, we can change the exponent in the equation to produce similar plots. The gif shows the effect of changing the exponent (varying from 0 to 10).
Another result, we take the complex conjugate before squaring, shown in the equtions:
This modified equation produces the following pattern known as the Tricorn.
The 3D extension to the 2D Mandelbrot set:
We perform 10 iterations and produce:
We perform 10 iterations and produce:
The animation shows the effect of performing further iterations. Eventually we get more detail than our plotting can handle.