Documentation
¶
Overview ¶
Package dynamical provides primitives for the study of discrete and continuous dynamical systems, implemented with the Go standard library only.
The package is organized around a handful of small concepts:
- Iterated one-dimensional maps (Map1D) such as the logistic, tent, sine, Gauss, cubic and circle maps, together with helpers to build parameterized families as closures.
- Iterated two-dimensional maps (Map2D) over Point2D values, most notably the Henon map.
- Orbits and trajectories: forward iteration with optional transient discarding, and single n-th iterate evaluation.
- Fixed points and their linear stability, including closed-form fixed points and multipliers for the logistic and tent maps.
- Lyapunov exponents estimated both from the analytic derivative and by the trajectory-separation (renormalization) method, in one and two dimensions.
- Bifurcation-diagram sampling for parameterized one-dimensional families.
- Period detection for periodic and eventually-periodic orbits.
- Cobweb (staircase) diagram segment data for visualizing 1-D iteration.
- Newton's method in the real and complex plane, and the basin-of- attraction grid produced by Newton iteration of a complex map.
- Continuous flows in three dimensions (Flow3D) integrated with a fixed-step classical Runge-Kutta (RK4) scheme, with the Lorenz and Rossler systems provided as concrete examples.
All routines are deterministic: given the same inputs they produce the same outputs, and no global random state is used.
Index ¶
- func CircleMap(omega, k, theta float64) float64
- func ClassifyRoot(roots []complex128, z complex128, tol float64) int
- func CubicMap(a, x float64) float64
- func DetectPeriod(f Map1D, x0 float64, transient, maxPeriod int, tol float64) int
- func DetectPeriod2D(f Map2D, p0 Point2D, transient, maxPeriod int, tol float64) int
- func Doubling(x float64) float64
- func FixedPoint1D(f, df Map1D, x0 float64, maxIter int, tol float64) (root float64, iters int, converged bool)
- func GaussMap(alpha, beta, x float64) float64
- func Henon(a, b, x, y float64) (float64, float64)
- func HenonJacobian(a, b float64, p Point2D) [2][2]float64
- func IsFixedPoint(f Map1D, x, tol float64) bool
- func IsPeriodicPoint(f Map1D, x0 float64, period int, tol float64) bool
- func Logistic(r, x float64) float64
- func LogisticDeriv(r, x float64) float64
- func LogisticFixedPoints(r float64) []float64
- func Lyapunov(f, df Map1D, x0 float64, transient, n int) float64
- func Lyapunov2D(f Map2D, jac func(Point2D) [2][2]float64, p0 Point2D, transient, n int) float64
- func LyapunovHenon(a, b float64, transient, n int) float64
- func LyapunovSeparation(f Map1D, x0, d0 float64, transient, n int) float64
- func Multiplier(df Map1D, x float64) float64
- func NewtonBasin(f, df func(complex128) complex128, roots []complex128, ...) [][]int
- func NewtonReal(f, df Map1D, x0 float64, maxIter int, tol float64) (root float64, iters int, converged bool)
- func NthIterate(f Map1D, x0 float64, n int) float64
- func Orbit(f Map1D, x0 float64, n int) []float64
- func OrbitTransient(f Map1D, x0 float64, transient, n int) []float64
- func QuadraticMap(c, x float64) float64
- func SineMap(r, x float64) float64
- func Tent(mu, x float64) float64
- func TentFixedPoints(mu float64) []float64
- type BifurcationPoint
- type CobwebSegment
- type Flow3D
- type LorenzParams
- type Map1D
- type Map2D
- type NewtonResult
- type Point2D
- type RosslerParams
- type Stability
- type Vec3
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CircleMap ¶
CircleMap evaluates the standard circle map f(theta) = theta + omega - (k/2pi)*sin(2pi*theta), reduced modulo 1. With k = 0 it reduces to rigid rotation by omega.
func ClassifyRoot ¶
func ClassifyRoot(roots []complex128, z complex128, tol float64) int
ClassifyRoot returns the index in roots of the entry nearest to z, provided that nearest entry lies within tol; otherwise it returns -1. It is used to label which basin of attraction a Newton iterate has fallen into.
func DetectPeriod ¶
DetectPeriod attempts to determine the period of the orbit of f starting at x0. It first iterates transient times to settle onto the attractor, records the resulting reference point, then searches for the smallest period p in 1..maxPeriod such that the p-th further iterate returns to within tol of the reference point. It returns that period, or 0 if none is found within maxPeriod (for example on a chaotic or very long orbit).
func DetectPeriod2D ¶
DetectPeriod2D is the two-dimensional analogue of DetectPeriod for a map of the plane, measuring return in Euclidean distance.
func FixedPoint1D ¶
func FixedPoint1D(f, df Map1D, x0 float64, maxIter int, tol float64) (root float64, iters int, converged bool)
FixedPoint1D finds a fixed point of the map f near x0 by applying Newton's method to g(x) = f(x) - x, using the analytic derivative df of f. It returns the located point, the number of iterations performed and whether the iteration converged to within tol.
func Henon ¶
Henon evaluates one step of the Henon map (x, y) -> (1 - a*x^2 + y, b*x) with parameters a and b.
func HenonJacobian ¶
HenonJacobian returns the 2x2 Jacobian matrix of the Henon map at point p, stored in row-major order: {{-2*a*x, 1}, {b, 0}}.
func IsFixedPoint ¶
IsFixedPoint reports whether x is a fixed point of f, that is whether |f(x) - x| <= tol.
func IsPeriodicPoint ¶
IsPeriodicPoint reports whether x0 is a periodic point of f with period exactly period, that is whether f^period(x0) returns to within tol of x0 while no smaller positive multiple of the iterate does. A period <= 0 returns false.
func Logistic ¶
Logistic evaluates the logistic map f(x) = r*x*(1-x) at x with parameter r. For r in [0,4] and x in [0,1] the unit interval is mapped into itself.
func LogisticDeriv ¶
LogisticDeriv evaluates the derivative f'(x) = r*(1-2x) of the logistic map.
func LogisticFixedPoints ¶
LogisticFixedPoints returns the fixed points of the logistic map with parameter r. There is always the origin 0; the second fixed point 1 - 1/r exists (and is distinct) for r != 0 and is returned whenever r is nonzero.
func Lyapunov ¶
Lyapunov estimates the Lyapunov exponent of the one-dimensional map f from the analytic derivative df. Starting at x0 it discards the first transient iterates, then averages log|df(x)| over the next n iterates. The result is the mean exponential rate of separation of nearby trajectories; a positive value indicates sensitive dependence on initial conditions (chaos).
For the tent map with slope mu the derivative has constant magnitude mu, so the estimate equals log(mu) exactly; for the logistic map at r = 4 it approaches log(2).
func Lyapunov2D ¶
Lyapunov2D estimates the largest Lyapunov exponent of a two-dimensional map f whose Jacobian at any point is supplied by jac (row-major 2x2). A tangent vector is transported along the orbit by repeated multiplication with the Jacobian and renormalized to unit length each step; the accumulated logarithmic growth divided by n is returned. The first transient iterates of the base orbit are discarded first.
func LyapunovHenon ¶
LyapunovHenon estimates the largest Lyapunov exponent of the Henon map with parameters a and b by Lyapunov2D, starting from the origin. For the classical parameters a = 1.4, b = 0.3 the exponent is approximately 0.419.
func LyapunovSeparation ¶
LyapunovSeparation estimates the Lyapunov exponent of the map f without an analytic derivative, using the trajectory-separation (renormalization) method. Two orbits are launched an initial distance d0 apart; after each step the separation is measured, its logarithmic growth accumulated, and the perturbed orbit rescaled back to distance d0. The first transient iterates are discarded before accumulation begins.
func Multiplier ¶
Multiplier evaluates the derivative df at x, i.e. the multiplier of the map at the point x. For a fixed point this determines its linear stability.
func NewtonBasin ¶
func NewtonBasin(f, df func(complex128) complex128, roots []complex128, xmin, xmax, ymin, ymax float64, nx, ny, maxIter int, tol float64) [][]int
NewtonBasin computes the Newton basin-of-attraction grid for the complex map f with derivative df over the rectangle [xmin,xmax] x [ymin,ymax], sampled on an nx-by-ny grid. Each grid point is used as a starting value for Newton's method; the resulting root is matched against the supplied roots by ClassifyRoot. The returned matrix has ny rows and nx columns in row-major order: entry [j][i] is the index of the root that the sample at column i, row j converged to, or -1 if it did not converge to any listed root.
func NewtonReal ¶
func NewtonReal(f, df Map1D, x0 float64, maxIter int, tol float64) (root float64, iters int, converged bool)
NewtonReal applies Newton's method x -> x - f(x)/f'(x) on the real line, starting at x0, using the function f and its derivative df. It returns the located root, the number of iterations performed, and whether |f(x)| <= tol was achieved.
func NthIterate ¶
NthIterate returns the n-th iterate f^n(x0) of the map f. For n <= 0 it returns x0 unchanged.
func Orbit ¶
Orbit returns the forward orbit x_0, x_1, ..., x_n of the one-dimensional map f starting from x0, that is a slice of length n+1 whose first element is x0 and whose k-th element is the k-th iterate of f applied to x0.
func OrbitTransient ¶
OrbitTransient iterates the map f from x0 discarding the first transient points, then returns the following n+1 points of the orbit. It is used to sample the attractor of f while suppressing initial transient behavior.
func QuadraticMap ¶
QuadraticMap evaluates the quadratic map f(x) = x^2 + c, the canonical form to which every real quadratic map is conjugate.
func Tent ¶
Tent evaluates the tent map at x with slope parameter mu: the value is mu*x for x < 1/2 and mu*(1-x) for x >= 1/2.
func TentFixedPoints ¶
TentFixedPoints returns the fixed points of the tent map with slope mu. The origin 0 is always fixed; for mu > 1 the point mu/(1+mu) in the right branch is fixed as well and is included.
Types ¶
type BifurcationPoint ¶
BifurcationPoint holds the sampled long-term states of a one-dimensional map at a single parameter value. Param is the parameter; Values are the attractor samples collected after discarding transients. Plotting Values against Param for many parameters yields a bifurcation diagram.
func Bifurcation ¶
func Bifurcation(family func(param float64) Map1D, pmin, pmax float64, steps int, x0 float64, transient, samples int) []BifurcationPoint
Bifurcation samples the asymptotic behavior of a one-parameter family of one-dimensional maps. For each of steps parameter values evenly spaced from pmin to pmax (inclusive), it builds the map family(param), iterates from x0 discarding transient points, then records the next samples iterates as the attractor samples for that parameter. It returns one BifurcationPoint per parameter value.
steps must be at least 1; a single step samples pmin only.
func LogisticBifurcation ¶
func LogisticBifurcation(rmin, rmax float64, steps int, x0 float64, transient, samples int) []BifurcationPoint
LogisticBifurcation is a convenience wrapper around Bifurcation for the logistic family x -> r*x*(1-x), sweeping r from rmin to rmax.
type CobwebSegment ¶
type CobwebSegment struct {
X0, Y0, X1, Y1 float64
}
CobwebSegment is one line segment of a cobweb (staircase) diagram, joining the point (X0, Y0) to (X1, Y1). Cobweb diagrams alternate vertical segments (from the diagonal up or down to the graph of f) with horizontal segments (from the graph across to the diagonal), visualizing the iteration of a one-dimensional map.
func Cobweb ¶
func Cobweb(f Map1D, x0 float64, n int) []CobwebSegment
Cobweb returns the segments of the cobweb diagram for n iterations of the map f starting at x0. The construction begins on the diagonal at (x0, x0) and, for each step, adds a vertical segment up to the graph (x, f(x)) followed by a horizontal segment across to the diagonal (f(x), f(x)). The result therefore contains 2*n segments (for n >= 0).
type Flow3D ¶
Flow3D is the vector field of a continuous three-dimensional dynamical system: it maps a state s to its time derivative ds/dt = f(s).
type LorenzParams ¶
type LorenzParams struct {
Sigma, Rho, Beta float64
}
LorenzParams holds the three parameters of the Lorenz system.
func DefaultLorenz ¶
func DefaultLorenz() LorenzParams
DefaultLorenz returns the classical chaotic Lorenz parameters sigma = 10, rho = 28, beta = 8/3.
func (LorenzParams) Field ¶
func (p LorenzParams) Field() Flow3D
Field returns the Lorenz vector field
dx/dt = sigma*(y - x) dy/dt = x*(rho - z) - y dz/dt = x*y - beta*z
as a Flow3D closure for these parameters.
func (LorenzParams) LorenzFixedPoints ¶
func (p LorenzParams) LorenzFixedPoints() []Vec3
LorenzFixedPoints returns the equilibria of the Lorenz system with parameters p. The origin is always an equilibrium; for rho > 1 the two symmetric points C+ and C- at (+-sqrt(beta*(rho-1)), +-sqrt(beta*(rho-1)), rho-1) are included.
type Map1D ¶
Map1D is a real function of one real variable, used as the iteration rule of a one-dimensional discrete dynamical system x_{n+1} = f(x_n).
func CircleRotation ¶
CircleRotation returns the rigid rotation theta -> theta + omega mod 1 as a Map1D closure.
func DoublingMap ¶
func DoublingMap() Map1D
DoublingMap returns the doubling map x -> 2x mod 1 as a Map1D closure.
func LogisticMap ¶
LogisticMap returns the logistic map x -> r*x*(1-x) as a Map1D closure for the fixed parameter r.
type Map2D ¶
Map2D is a map of the plane to itself, used as the iteration rule of a two-dimensional discrete dynamical system p_{n+1} = f(p_n).
type NewtonResult ¶
type NewtonResult struct {
Root complex128
Iterations int
Converged bool
}
NewtonResult holds the outcome of a complex Newton iteration: the point Root reached, the number of Iterations performed, and whether the iteration Converged to within the requested tolerance.
func NewtonComplex ¶
func NewtonComplex(f, df func(complex128) complex128, z0 complex128, maxIter int, tol float64) NewtonResult
NewtonComplex applies Newton's method z -> z - f(z)/f'(z) in the complex plane, starting at z0, using the function f and its derivative df. It stops when |f(z)| <= tol (reporting convergence) or after maxIter steps.
type Point2D ¶
type Point2D struct {
X, Y float64
}
Point2D is a point in the plane, used as the state of a two-dimensional discrete dynamical system.
func HenonFixedPoints ¶
HenonFixedPoints returns the real fixed points of the Henon map with parameters a and b. They are the solutions of a*x^2 + (1-b)*x - 1 = 0 with y = b*x; the slice is empty when the discriminant is negative and has one or two entries otherwise.
func NthIterate2D ¶
NthIterate2D returns the n-th iterate f^n(p0) of the two-dimensional map f.
func Orbit2D ¶
Orbit2D returns the forward orbit p_0, p_1, ..., p_n of the two-dimensional map f starting from p0, as a slice of length n+1.
func OrbitTransient2D ¶
OrbitTransient2D iterates the map f from p0 discarding the first transient points, then returns the following n+1 points of the orbit.
type RosslerParams ¶
type RosslerParams struct {
A, B, C float64
}
RosslerParams holds the three parameters of the Rossler system.
func DefaultRossler ¶
func DefaultRossler() RosslerParams
DefaultRossler returns commonly used chaotic Rossler parameters a = 0.2, b = 0.2, c = 5.7.
func (RosslerParams) Field ¶
func (p RosslerParams) Field() Flow3D
Field returns the Rossler vector field
dx/dt = -y - z dy/dt = x + a*y dz/dt = b + z*(x - c)
as a Flow3D closure for these parameters.
type Stability ¶
type Stability int
Stability classifies the linear stability of a fixed or periodic point of a one-dimensional map according to the magnitude of its multiplier (the map derivative there).
const ( // Unstable indicates a multiplier of magnitude strictly greater than one: // nearby orbits move away from the point. Unstable Stability = iota // Stable indicates a multiplier of magnitude strictly less than one: // nearby orbits are attracted to the point. Stable // Neutral indicates a multiplier of magnitude exactly one (to within the // requested tolerance): linear analysis is inconclusive. Neutral // SuperStable indicates a zero multiplier, giving especially fast // (quadratic) local convergence. SuperStable )
func ClassifyStability ¶
ClassifyStability classifies a fixed point by its multiplier m using tolerance tol to decide the borderline neutral case |m| == 1. A multiplier of exactly zero is reported as SuperStable.
func LogisticStability ¶
LogisticStability returns the stability class of each fixed point returned by LogisticFixedPoints for parameter r, using tolerance tol for the neutral case. The multiplier at 0 is r and at 1 - 1/r is 2 - r.
type Vec3 ¶
type Vec3 struct {
X, Y, Z float64
}
Vec3 is a point or vector in three-dimensional space, used as the state of a continuous dynamical system.
func Integrate3D ¶
Integrate3D integrates the vector field f from the initial state s0 for n steps of size dt using RK4Step3D, returning the trajectory as a slice of length n+1 whose first element is s0.
func LorenzTrajectory ¶
func LorenzTrajectory(p LorenzParams, s0 Vec3, dt float64, n int) []Vec3
LorenzTrajectory integrates the Lorenz system with parameters p from state s0 for n RK4 steps of size dt, returning the trajectory (length n+1).
func RK4Step3D ¶
RK4Step3D advances the state s by one step of size dt under the vector field f using the classical fourth-order Runge-Kutta method, returning the new state. The local truncation error is O(dt^5) per step.
func RosslerTrajectory ¶
func RosslerTrajectory(p RosslerParams, s0 Vec3, dt float64, n int) []Vec3
RosslerTrajectory integrates the Rossler system with parameters p from state s0 for n RK4 steps of size dt, returning the trajectory (length n+1).