Google.com

Chaotic Dynamics System Modeling in C++.

Markus Buchholz
Geek Culture
Published in
7 min readOct 22, 2022

--

In the following article, I will depict a fundamental overview of the dynamical system and give you general intuition of model representation. In the second part, I will display an introduction to the chaotic theory concerning dynamic systems (chaotic dynamics). I will depict interesting systems which will be simulated using C++ (code on my GitHub).

The header file (for plotting library) has to be in the same folder as your cpp (a file you can clone from my repository).
Your program can be compiled as follows,

//compile
g++ my_prog.cpp -o my_prog -I/usr/include/python3.8 -lpython3.8//
//run
./my_prog
//folder tree
├── my_prog
├── my_prog.cpp
├── matplotlibcpp.h

Dynamical System.

Systems that change over time are called dynamic systems and are characterized by one or more equations. Dynamic equations, for instance, can be used to explain population changes, weather, or robot movement. Dynamical systems will be described by differential equations, which involve the derivative (the instantaneous change) of a function.

Since we need to capture the intuition I will explain all the components of the dynamic equation (differential equation).

Vector X represents the state of our system, which has the minimal number set of values, which we need to describe our system (behavior). If I analyze the pendulum, the system is uniquely defined by its angle theta and angular velocity around the pivot.

F is what we call the dynamics and it is a set of functions f1, f2, f3, … fn that describes the dynamics of state 1 state 2 state 3, and state n. The function F is a vector field that provides information on how the system will change in time based on current state X. We called F a vector field since it gives us for each state space X information about the direction of how vector derivative.

t, as expected, is the time and it is a fundamental “component” of dynamic systems that describes how the system is changing over time.

Vector uis associated with the active control of the dynamic system. When we drive a car we can move faster by affecting the speed pedal. This is our external input (control signal) to the system affecting the response.

𝛽 is a component that includes other parameters of the system which we can not control explicitly but changes in the value can change the system's dynamic behavior (response). If we consider again the car. Car dynamic (response) will differ when the car will be driven by one person without passengers and the situation when the car is a full load (maximum number of passengers and pieces of baggage).

We can not forget about also about the other disturbances d like the notice in the system, inaccuracy, or decreased quality of the mechanical system we try to control.

I seem to be very important to mention something about the challenges we face to build the dynamic model of the system and affects on its behavior.

  1. Generally, the dynamic system can be described by Newton’s laws, the Lagrangian or the Hamiltonian, however, these equations only approximate the reality since often the system is complex and described by many parameters, variables, and relations. Sometimes we do not have the access to these parameters since they are not measurable or difficult to extract, or we do not know about their existence or relations. Normally we use models which approximated the “real world or real behavior”.
  2. The second important challenge connected with the equation used in order to describe the dynamic is nonlinearity (meaning the superposition — additivity, and homogeneity are not satisfied). These systems are difficult to synthesize and analyze.
  3. In a dynamic system — vector X has many dimensions. Weather or the human brain can be described by many variables, often unknown or unpredictable. The challenge here is to choose the ones which are mostly affected by the system dynamics.
  4. The dynamics of the system can be also chaotic (we are going to be closer in the next section of the following article). Generally, it means the system dynamics can be very sensitive to small changes in (parameter 𝛽), initial conditions, or hidden states. As I discussed before in my article about Lorenz attractor, small changes at the initial state affect the extreme changes after a certain of time. It means— sensitive to small changes, initial conditions, or other model parameters.
  5. All parameters which describe the system can be associated with uncertainty since all components of the dynamic model we use are uncertain (stochastic)— we can define the probability of how we affect the system, what we measure, how we measure, we are uncertain even about the time (the system can have some delay), etc.

As you can see the dynamic system can be hard to model, operate and affect over time. If you need more information I encourage you to study the control systems domain and/or watch prof Steve Brunton's YouTube channel or TechTalk by Brian Douglas available here and here.

Chaos.

Chaos theory is relevant to deterministic systems whose behavior is theoretically predictable. Chaotic systems initially appear to be predictable before turning out to be random, the behavior of such systems can not be determined.
Note. All simulations in C++ depicted here are available on my Github.

We can define the time for which the system behavior is chaotic. However, it depends on three parameters:

  1. the amount of uncertainty can be tolerated in the prediction,
  2. how accurately its current state can be measured,
  3. and a time scale depending on the dynamics of the system.

There is no universally accepted definition for chaos, but the following
characteristics are always depicted by the solutions of chaotic systems:

  1. long—term aperiodic system behavior,
  2. sensitivity to initial conditions (please take a look at my previous article where I discussed Lorenz attractor),
  3. fractal structure
Wikipedia

A strange attractor, (chaotic attractor, fractal attractor ) is an
attractor that exhibits sensitivity to initial conditions. In the following example, we can plot the solution of the differential equation on the Lorenz model that has been discovered (modified) by Guanrong Chen and Tetsushi Ueta → (Multiscroll attractor).

The dynamics of the chaotic system is described as follows,

A numerical solution can be depicted as follows,

A strange attractor when a= 35, b = 3, and c= 28.

The next example where chaotic phenomena can be observed is Chua’s circuit. The circuit displays many interesting phenomena including period-doubling cascades to chaos, intermittency routes to chaos, and quasiperiodic routes to chaos.

Chua’s circuit (by author)

The dynamics of the chaotic system is described as follows,

g(x) describes the electrical response of the nonlinear resistor,
and its shape depends on the particular configuration of its components.

The parameters a, b, c, and d are determined by the particular values of the circuit components.

A numerical solution can be depicted as follows,

Chua’s double-scroll attractor

Otto E. Rössler constructed the following three-dimensional
system of differential equations:

where a, b, and c are all constants.

A numerical solution can be depicted as follows,

The chaotic attractor for the system when c = 6. 3
The chaotic attractor for the system when c = 6. 3. x(t) curve

You can see what happens if the initial condition only for x will slightly be changed.

The chaotic attractor for the system when c = 6. 3. x(t) curve for change initial conditions.

We can also derive the dynamic system as follows,

a = 17, b =16

and solve numerically,

The solution curve for the above system

Next, we can simulate the Hamiltonian System with Two Degrees of
Freedom.

The dynamic system can be depicted as follows,

In general, only a very small but significant subset of the set of Hamiltonian systems with two degrees of freedom is fully integrable. These systems’ paths are in four dimensions, but by drawing Poincaré maps, the general structure can be ascertained. In contrast to nonintegrable systems, which can exhibit a wide range of phenomena, including chaotic behavior, completely integrable systems are known to exhibit exceptional smooth regular behavior in all regions of the phase space. Following a brief explanation of integrability, we shall define Hamiltonian systems with two degrees of freedom.

The numerical solution as follows,

Projections of the Poincaré surface-of-section for the system
Projections of the Poincaré surface-of-section for the system p1(q1)

In our last example we will consider a periodically driven pendulum, which can be shown as follows:

periodically driven pendulum )by author)

The second-order dynamic system can be described by Duffing equation

where, in physical models, k ≥ 0 is the damping coefficient, β is the stiffness, α is the nonlinear stiffness parameter, x is the position of the mass, 𝛾 is the amplitude of forced vibration, and ω is the frequency of the driving force.

The numerical solution can be presented as follows,

Poincaré map for discussed system

Thank you fore reading.

--

--