lorenz#
- class peccary.examples.lorenz(s=10, r=20, b=2.667, initialVals=(0.0, 1.0, 1.05))[source]#
Bases:
objectThe
lorenzclass can be used to generate the x-, y-, and z-coordinates of the Lorenz strange attractor, which is chaotic for certain values of the input parameters \(\sigma\), \(\rho\), and \(\beta\).References
[1] Code modified and expanded from a Matplotlib tutorial
Examples
To initialize the class using the default input parameters (\(\sigma = 10\), \(\rho = 20\), \(\beta = 2.667\)) and initial values (\(x_0 = 0\), \(y_0 = 1\), \(z = 1.05\)), run the following code:
>>> import peccary.examples as ex >>> lorenzSys = ex.lorenz()
To integrate the system, use the
integratemethod. The timestep resolution can be controlled with thedtparameter (default 0.01) and either the number of timestepsnsteps(default 10000) or the duration parametertDurfor the number of “seconds”. ThetDurparameter is by default not used, but when specified, it supersedesnsteps. To integrate the initialized system for 250.0 seconds, run:>>> lor = lorenzSys.integrate(tDur=250.0)
The 3D data is stored in a
peccary.timeseries.Timeseriesclass with the attributesx,y, andz, with the timesteps stored in thetattribute. The data can be extracted and plotted, e.g.,>>> import matplotlib.pyplot as plt >>> ax = plt.figure().add_subplot(projection='3d') >>> ax.plot(lor.x, lor.y, lor.z, lw=0.5) >>> plt.show()
Methods Summary
getPartials(xyz)Get partial derivatives for initialized Lorenz system
integrate([dt, nsteps, tDur])Integrate x/y/z timeseries for Lorenz strange attractor
Methods Documentation
- getPartials(xyz)[source]#
Get partial derivatives for initialized Lorenz system
- Parameters:
- xyzndarray
3D array containing points of interest in three-dimensional space
- Returns:
- ndarray
3D array containing partial derivatives at xyz
- integrate(dt=0.01, nsteps=10000, tDur=None)[source]#
Integrate x/y/z timeseries for Lorenz strange attractor
- Parameters:
- dtfloat, optional
Timestep resolution, by default 0.01
- nstepsint, optional
Number of timesteps to integrate, by default 10000
- tDurfloat, optional
Duration of time to integrate over, supersedes nsteps, by default None
- Returns:
- peccary.timeseries.Timeseries
Timeseries for x-, y-, and z- coordinates of Lorenz strange attractor, stored in
x,y, andzattributes ofTimeseriesclass
- Attributes:
- dtfloat
Timestep resolution
- nstepsint
Number of timesteps used in integration
- tDurNone or float
Duration of timseries, None unless specified
- tNone or ndarray
Array of timesteps corresponding to timeseries
- t0float
Initial time for integration