Paper Oscillator
Paper Oscillator
Received: October 19, 2021. Revised: October 23, 2022. Accepted: November 25, 2022. Published: January 25, 2023.
the non-linearity in a system means that the measured For our purpose, we will use the numpy which is a
values in the output of the system are not propor- Python library used for working with arrays, and the
tional to the values of the input. The presence of non- matplotlib which is a plotting library for the Python
linearity in a system does not mean that the system programming language.
will behave chaotically but a form of non-linearity if
required to achieve chaotic behavior, [9]. A system # Oscilator
showing chaotic behavior undergoes transitions be- from s c i p y . i n t e g r a t e import o d e i n t
tween non-chaotic and chaotic states in general, [10]. import numpy a s np
A similar approach could be found in [11] where the import m a t p l o t l i b . p y p l o t a s p l t
transition to chaos is made by changing the angular # System Parameters
frequency of external force, in our approach the tran- [ k , m] = [ 9 , 1 ]
sition to chaos is made by changing the amplitude of # I n i t i a l Conditions
the external force applied to the system. x = [5 ,0]
# Simulation parameters
N = 1000
1 Simple oscillator t = np . l i n s p a c e ( 0 , 1 0 ,N)
We begin our pedagogical method by using the inte- def f ( x , t ) :
gration method on a well-known problem such as that d v d t = −( k /m) * x [ 0 ]
of the oscillator. dxdt = x [1]
return [ dxdt , dvdt ]
solution = odeint ( f , x , t )
The above code implements the solution. The
code can be easily understood by someone who has
no programming knowledge. In the beginning, the
necessary packages are loaded into the program. The
commands for the system parameters and the ini-
Fig. 1: Simple Harmonic Oscillator with a spring tial conditions are given following with the function
mass system f(x,t) with the differential equations of the system.
The function odeint solves the system and the results
In figure 1 a simple harmonic oscillator with a are saved to variable solution
spring mass system is presented. Since the constant
of elasticity of the spring is denoted with k and the plt . plot ( t , solution [: ,0])
mass of the object with m, we can express the differ- plt . x l a b e l ( ’ Time t [ s ] ’ )
ential equation of the motion of the system as follows: plt . y l a b e l ( ’ x [m] ’ )
plt . show ( )
d2 x To plot the solution which we are getting from
m = −kx (1)
dt2 odeint, the above code is used. The presented code
the system is governed by a second-order linear dif- uses the library matplotlib which has a very similar
ferential equation, [12]. To apply a numerical method syntax to MATLAB. The result is presented in figure (2)
of integration for equation (1) we rewrite it as a pair of from were the sinusoidal correlation of the position of
first-order differential equations, which are presented the oscillator in relation to time can be seen.
at equation (2). The phase space of the system is created with some
minor changes to the above code. (fig. 3). The phase
dv k dx diagram gives us an overview of the evolution of the
=− x and =v (2)
dt m dt system. Τhe position of the oscillator is shown on the
horizontal axis, while its speed is on the vertical axis.
We suppose the system with parameters k = Furthermore, from the Fig. 3 we observe that the pe-
9 N /m and m = 1 kg and with initial conditions riod of the system is √ T = 2.09 s as we expect from
x = 5 m and v = 0 m/s. The simulation will cal- the relation T = 2π/ k/m
culate the position and velocity for the time interval
of the oscillator from t = 0 s to t = 10 s. Will be cal-
culated N = 1000 points of the trajectory. Increas- 2 Driven damped pendulum
ing the sampling (N>1000) of the trajectory would Considering a simple pendulum in a constant gravita-
require more computing power to achieve the solu- tional field as it is presented in fig. 4. The equation of
tion, while reducing it would result in an increase motion is given by the differential equation 3 where
in the computational error of the numerical method. its current angle is denoted by θ and angular velocity
2
x[m]
0 2 4 6 8 10
Time t[s]
0 import m a t p l o t l i b . p y p l o t a s p l t
5 # System Parameters
10 [ g , L , b ] = [ 1 0 , 10 , 0 . 5 ]
[w , A] = [ 2 / 3 , 1 ]
15
# I n i t i a l Conditions
4 2 0 2 4
x[m] θ = [0.5 ,0]
# Simulation parameters
Fig. 3: Phase space of the harmonic oscillator N = 20000
t = np . l i n s p a c e ( 0 , 2 0 0 ,N)
def f (θ , t ) :
by θ̇. d v d t = −( g / L) * np . s i n ( θ [ 0 ] ) . . .
−mlθ̈ = mg sin(θ) (3) . . . − b*θ [ 1 ] +A* np . s i n (w* t )
dθ d t = θ [ 1 ]
The reason that the small-angle approximation is r e t u r n [ dθ d t , d v d t ]
made is that otherwise the differential equation which solution = odeint ( f ,θ , t )
describes the system could not be solved using analyt- We run the code and the results are saved in the
ical methods. The solution of the equation could eas- variable “solution”. The time needed for the solu-
ily get using the code below. Regardless of the initial tion is relatively short although the number of cal-
conditions, the system will go to a steady state. [11] culation points is significantly larger. Then we pro-
Equation (4) shows the differential equation of a ceed with the creation of the corresponding graphical
damped-driven pendulum. The motion of the pendu- representations of the angular displacement with time
lum is damped by a force proportional to its velocity and phase space.
which is expressed in the equation with the term −β θ̇. The graph is shown in Fig. 5 where we see that
Moreover, equation (4) represents a pendulum with a after the time of 100 seconds the system performs
time-varying external force with amplitude A and fre- harmonic oscillation of constant amplitude and fre-
quency ω expressed by the term A sin(ωt). quency. At this point we let the students experiment
g with the various initial conditions of the system. By
θ̈ = − sin θ − β θ̇ + A sin(ωt) (4) choosing different initial conditions we see that the
L system exhibits the same behavior and finally per-
For solving the differential equation (4) we con- forms harmonic oscillations.
sider a system with parameters, g = 10 m/s2 , L = To construct the phase diagram we will use the
10 m, β = 0.5 N s/m, A = 1 N and ω = 2, 3 rad/s. states of the system after harmonic oscillation is
The simulation starts from initial position θ = 0.5 rad reached. We should also ensure that the value of the
Speed [rad/s]
1
[rad]
0 0
1
1
2
2
3 o=1.0, = 0.5, A=1, =0.667
0 25 50 75 100 125 150 175 200 3 2 1 0 1 2 3
Time t[s] Position [rad]
Fig. 5: Position of the oscillator vs time Fig. 7: Phase space of the system with A = 1.35 N
angle should not exceed the range −π ≤ θ ≤ π . o=1.0, = 0.5, A=1.45, =0.667
2
o=1.0, = 0.5, A=1, =0.667
1
2 Speed [rad/s]
0
1
Speed [rad/s]
1
0
2
1
3 2 1 0 1 2 3
Position [rad]
2
2 1 0 1 2 3 Fig. 8: Phase space of the system with A = 1.45 N
Position [rad]
Fig. 6: Phase space of the system with A = 1 N as it shown in Fig. 10. It has to be mentioned that
the motion of the system is not random. There is
In order to bring the system described by the equa- a periodicity but the period is large enough. This
tion (4) in chaotic operation we use the method of makes a small observation of the operation look to-
period doubling by changing the amplitude of the tally stochastic. In this state, the system is called a
external force. We have changed the angular fre- strange attractor. In this situation, a small change in
quency of the external force to ω = 2/3 rad/s and the initial conditions of the system will cause a big
we change the amplitude of the external force to A = difference in its motion, regardless that the shape of
[1.35, 1.45, 1.47, and 1.5] the phase space will not change.
The transition to chaos is shown in figure 7 where The chaotic operation could be characterized by
the phase space of the system is presented when the the rate of separation of infinitesimally close trajecto-
amplitude of the driving force is A = 1.35. The tra- ries. this is done by the calculation of the Lyapunov
jectory of the system in the phase space diagram is a exponent described below. The presence of chaos is
closed loop as expected. Increasing the amplitude to verified also in electronic circuits [13].
A = 1.45 the trajectory in the phase space is chang-
ing, and a second path is appearing denoting the pe- 3 Lyapunov exponent calculation
riod doubling of the system as it is shown in fig. 8. The chaotic behavior of a systems is verified by the
By increasing the amplitude to A = 1.47 the phase calculation of the Lyapunov exponent, [14]. The cal-
space diagram of the system changes again as it is pre- culation of this exponent is done by equation (5):
sented in figure 9. The system doubles its period, but
its behavior is still predictable.
1 ∑
N
δt,j
By choosing the amplitude of the external force δt ∼
= δ0 eλt λ= log (5)
A = 1.5 the operation of the system becomes chaotic N δ0,j
j=1
1 106
Speed [rad/s]
[radians]
0 104
1 102
2 100
Fig. 9: Phase space of the system with A = 1.47 N Fig. 11: Exponential increase of the difference be-
tween two very close orbits with respect to time. The
red line represents the linear regression.
o=1.0, = 0.5, A=1.5, =0.667
2
4 Discussion
1 This approach is applied in the context of the Compu-
Speed [rad/s]
stiff oscillatory ordinary differential equations,” [10] H. Nagashima, Y. Baba, and M. Nakahara, In-
ACM Transactions on Mathematical Software troduction to chaos: physics and mathematics
(TOMS), vol. 10, no. 1, pp. 58–72, 1984. of chaotic phenomena. CRC Press, 2019.
[3] P. Borcherds, “Python: a language for computa- [11] E. Ayars, “Computational physics with python,”
tional physics,” Computer Physics Communica- California State University, 2013.
tions, vol. 177, no. 1, pp. 199–201, 2007. Pro-
[12] K. N. Anagnostopoulos, Computational
ceedings of the Conference on Computational
Physics, Vol I: A Practical Introduction to Com-
Physics 2006.
putational Physics and Scientific Computing.
[4] B. W. l. Margolis, “Simupy: A python frame- Konstantinos Anagnostopoulos, 2014.
work for modeling and simulating dynamical [13] M. Hanias, I. Giannis, and G. Tombras, “Chaotic
systems,” Journal of Open Source Software, operation by a single transistor circuit in the
vol. 2, no. 17, p. 396, 2017. reverse active region,” Chaos: An Interdisci-
[5] D. R. Gwynllyw, K. L. Henderson, E. G. Guil- plinary Journal of Nonlinear Science, vol. 20,
lot, et al., “Using python in the teaching of nu- no. 1, p. 013105, 2010.
merical analysis.,” MSOR Connections, vol. 18, [14] J. Jani and P. Malkaj, “Numerical calculation of
no. 2, 2020. lyapunov exponents in various nonlinear chaotic
systems,” International Journal of Scientific &
[6] J. Nunez-Iglesias, S. Van Der Walt, and H. Dash-
Technology Research, vol. 3, no. 7, pp. 87–90,
now, Elegant SciPy: The art of scientific python.
2014.
” O’Reilly Media, Inc.”, 2017.
[7] J. Kusalaas, “Numerical methods in engineering
Contribution of Individual Authors to the
with python 3,” 2013.
Creation of a Scientific Article (Ghostwriting
[8] A. BenSaïda, “A practical test for noisy chaotic Policy)
dynamics,” SoftwareX, vol. 3-4, pp. 1–5, 2015. The author contributed in the present research, at all
stages from the formulation of the problem to the
[9] S. Strogatz, Nonlinear Dynamics and Chaos: final findings and solution.
With Applications to Physics, Biology, Chem-
istry, and Engineering. CRC Press, 2018. Sources of Funding for Research Presented in a
Scientific Article or Scientific Article Itself
No funding was received for conducting this study.
Conflict of Interest
The author has no conflict of interest to declare that
is relevant to the content of this article.