Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thurs Oct 7 19:38:57 2021
@author: David Nolte
Introduction to Modern Dynamics, 2nd edition (Oxford University Press, 2019)
FlipPhone Example
"""
import numpy as np
from scipy import integrate
from matplotlib import pyplot as plt
plt.close('all')
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection='3d')
ax.axis('on')
I1 = 0.45
I2 = 0.5
I3 = 0.55
def solve_lorenz(param, max_time=300.0, angle=0.0):
# Flip Phone
def flow_deriv(x_y_z, t0):
x, y, z = x_y_z
yp1 = ((I2-I3)/I1)*y*z;
yp2 = ((I3-I1)/I2)*z*x;
yp3 = ((I1-I2)/I3)*x*y;
return [yp1, yp2, yp3]
model_title = 'Flip Phone'
t = np.linspace(0, max_time/4, int(250*max_time/4))
# Solve for trajectories
x0 = [[0.01,1,0.01]]
t = np.linspace(0, max_time, int(250*max_time))
x_t = np.asarray([integrate.odeint(flow_deriv, x0i, t)
for x0i in x0])
x, y, z = x_t[0,:,:].T
lines = ax.plot(x, y, z, '-')
plt.setp(lines, linewidth=0.5)
ax.view_init(30, angle)
plt.show()
plt.title(model_title)
plt.savefig('Flow3D')
return t, x_t
ax.set_xlim((-1.1, 1.1))
ax.set_ylim((-1.1, 1.1))
ax.set_zlim((-1.1, 1.1))
t, x_t = solve_lorenz(max_time,angle=30)
plt.figure(2)
lines = plt.plot(t,x_t[0,:,0],t,x_t[0,:,1],t,x_t[0,:,2])
plt.setp(lines, linewidth=1)