lorenz#

class peccary.examples.lorenz(s=10, r=20, b=2.667, initialVals=(0.0, 1.0, 1.05))[source]#

Bases: object

The lorenz class 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 integrate method. The timestep resolution can be controlled with the dt parameter (default 0.01) and either the number of timesteps nsteps (default 10000) or the duration parameter tDur for the number of “seconds”. The tDur parameter is by default not used, but when specified, it supersedes nsteps. 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.Timeseries class with the attributes x, y, and z, with the timesteps stored in the t attribute. 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, and z attributes of Timeseries class

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