Computational modeling and simulation On the properties of numerical solutions of dynamical systems obtained using the midpoint method

The article considers the midpoint scheme as a finite-difference scheme for a dynamical system of the form ̇𝑥 = 𝑓(𝑥) . This scheme is remarkable because according to Cooper’s theorem, it preserves all quadratic integrals of motion, moreover, it is the simplest scheme among symplectic Runge-Kutta schemes possessing this property. The properties of approximate solutions were studied in the framework of numerical experiments with linear and nonlinear oscillators, as well as with a system of several coupled oscillators. It is shown that in addition to the conservation of all integrals of motion, approximate solutions inherit the periodicity of motion. At the same time, attention is paid to the discussion of introducing the concept of periodicity of an approximate solution found by the difference scheme. In the case of a nonlinear oscillator, each step requires solving a system of nonlinear algebraic equations. The issues of organizing computations using such schemes are discussed. Comparison with other schemes, including those symmetric with respect to permutation of 𝑥 and ̂𝑥 .


Introduction
One of the most common and popular mathematical models is the Cauchy problem for an autonomous system of ordinary differential equations. Analytical methods make it possible to find the algebraic integrals of motion [1] for such systems, and numerical methods allow approximate plotting the particular solutions [2]. Consider an autonomous system of differential equations in an affine space of dimensioṅ= ( ).
Here = ( 1 , … , ) is a point in the affine space, = ( 1 , … , ) is a set of rational functions belonging to ℚ( ). Except the cases where it leads to ambiguity, we will use the vector notatioṅ= ( ). By the algebraic integral of motion of this system, we mean the algebraic function , constant on any particular solution of the system (1), i.e., satisfying the equation 1 1 It can be shown that the existence of an algebraic integral implies the existence of a rational integral, therefore only rational integrals are considered below [3].
The finite difference method is a standard numerical method for solving systems of ordinary differential equations [2]. The finite-difference scheme for solving the system of equations (1) describes the transition from the value of taken at some instant of time to the value of taken at the next instant of time + Δ . This new value will be denoted below by. Of course, by the difference scheme for the system (1) we understand a correspondence in some sense approximating the system of differential equations, rather an arbitrary correspondence between the variables and. Usually, by this approximation we mean that the system of equations defining the difference scheme tends to the original system as Δ → 0. Definition 1. By a particular solution of the system (1), found using the finite-difference scheme, we mean a finite or infinite sequence of points (0) , (1) , (2) , … , ( ) , … of the -dimensional space (or subset considered in it), the first element of which is taken arbitrarily, and each next element is obtained from the previous one according to the difference scheme: scheme is used, which does not preserve this integral. Therefore, in numerical experiments, it is often nothing to do but to observe with regret how the quantity which remains constant on the exact solution, changes step by step. Very frequently, the integrals of motion express fundamental laws of nature, the violation of which introduces new properties into the mathematical model under consideration, or trivial geometric relationships, the violation of which makes it difficult to interpret the results of integration.
The idea of contructing finite-difference schemes exactly preserving the integral of motion of dynamical systems was proposed in late 1980s in the papers by Yu. B. Suris [4] and Cooper [5], approaching the problem from different sides, namely, Yu. B. Suris from composing difference schemes for Hamiltonian systems that preserve a symplectic structure, and Cooper from preserving integrals. As a result, a large family of Runge-Kutta schemes was discovered that preserve all quadratic integrals of any dynamical system and the symplectic structure of the Hamiltonian system [6].
The simplest of this class of schemes is the midpoint scheme. By construction, the approximate solutions found using this scheme retain all quadratic integrals. Traditionally, the question of 'improvement' of convergence due to the conservation of integrals remained in the focus of attention. In this article, we intend to clarify what other qualitative properties of the exact solution are inherited by the approximate one. For completeness, we give an elementary proof of Cooper's theorem.

Conservation of quadratic integrals
Let be an integral of the system of Eqs. 1. According to Lagrange theorem about the mean value, where the derivatives are calculated at the point , lying somewhere in the segment connecting the points and, i.e., = + Δ , ∈ (0, 1).
The Lagrange theorem ensures the existence of a suitable function ( ,), taking the values between 0 and 1 at the real values of ,. However, it provides no method to find this function. If we knew such a function, we could easily construct a difference scheme that preserves the manifold = 0 exactly. Indeed, let Then and this expression is exactly equal to zero due to (2). For some classes of functions, the Lagrange theorem allows a constructive formulation.

Lemma 1.
If is a polynomial from ℂ[ 1 , … ], the degree of which does not exceed 2 inclusively, then

Proof. Let be a new auxiliary variable and
According to the Lagrange theorem, there is such value ∈ (0, 1), that or, in more detail, We have to prove that = 1/2. By the hypothesis of the lemma, is a polynomial whose degree does not exceed 2, therefore ″ is a polynomial with respect to whose degree does not exceed 2, i.e.
But then the Lagrange formula (4) reduces to + = 2 + , from which it immediately follows that = 1/2. The finite-difference scheme (3) at = 1/2, i.e., the scheme is called the midpoint scheme. Lemma 1 immediately leads to the following theorem.

Harmonic oscillator
Consider the simplest dynamical system describing a harmonic oscillator. This system is Hamiltonian, the energy conservation law for it yields the integral 2 + 2 = .
Usually it is immediately said without further ado that the solutions of this system describe periodic rotations along concentric circles in the phase plane .
The standard discretization does not allow to preserve this description. Consider for definiteness, the explicit Euler scheme  Figure 1 presents the curve in the phase plane, obtained using the Euler method instead of a unit circle. Thus it is easy to describe the difference between the exact and approximate solutions. Instead of closed curves, a spiral in the phase plane appears, or, in terms of classical mechanics, the time discretization leads to gradual increase of the system energy.
and try to understand the qualitative difference between the approximate solution and the exact one. According to Cooper's theorem, this difference scheme exaclty preserves this integral. Therefore, in the phase plane we get ovals that seemingly do not differ from a circle (see Figure 1). However, these curves are still not closed, and the motion along them cannot be considered perodic, since the values of , do not repeat. Therefore, it could be executed that the absence of closedness and periodicity completely allows one to distinguish between the approximate solution and the exact one. In fact, it is possible to achieve the solution relativity by the appropriate step choice.

Theorem 2. If we take for the minimal positive root of the equation
which in terms of trigonometric functions can be expressed as then the calculation according to the meanpoint finite-difference scheme (7) with the step Δ = 2 = 2 tan , in steps leads to the initial values of , .

Remark 1.
For us it is convenient to use the transcendent formula = tan , however, one could do without it using purely algebraic means. To emphasize this fact, in the statement of the theorem we have preserved the algebraic equation, for which this number is a root.
For proof, let us express,̂in terms of , , denoting for brevity Then Inverting the matrix, we get now the proof of theorem 2 is reduced to the proof of the following purely algebraic lemma.

Lemma 2.
If we take for the minimal positive root of equation (8), which in terms of trigonometric functions can be written as = tan , then 2 is a unit matrix.

Proof. Set for brevity
Assume that we performed steps of the finite-difference scheme, having started from the values , at a certain value = 0, and finished with , at = Δ . Then The eigenvalues of the matrix are When a matrix is raised to a power, its eigenvalues are raised to this power, too.
The equation 2 1 = 1 (10) can be satisfied assuming that The equality (10) can be rewritten in the form of the algebraic equation (8); in this way the minimal positive root of this equation has been found.
At real Δ from the equality (10) the equality 2 2 = 1 follows. In this case both eigenvalues of the matrix 2 are equal to 1. The eigenvectors of matrix are also eigenvectors of any power of this matrix, therefore, in this case two linearly independent eigenvectors correspond to the unit eigenvalue. This is possible only if the matrix 2 coincides with the unit matrix.
The proved theorem gives rise to the following definition.

Definition 2. The particular solution
found using a certain finite-difference scheme approximating the system (1), at a certain numerical value of the step Δ will be called periodic, if for some ∈ ℕ ( ) = .
The number Δ will be called a period of this particular solution.
Theorem 2 means that the midpoint scheme (7) yields periodic solutions at a number of step values that form a descending sequence: converging to zero. The corresponding sequence of periods converges to the exact solution period 2 . Thus, the second most important qualitative property of the exact solution, i.e., its periodicity, can be preserved, too. Moreover, even for small values of , in this way it is possible to get a solution that is qualitatively similar to the exact one.
For example, for = 10 and the step value we arrive at a periodic scheme with the period = 10Δ , that differs from the period of the exact solution by a noticeable value of In the phase plane a regular decagon is obtained that obviously differs from a circle, too. However, even in this case the trajectory in the phase plane is exactly closed and the motion is periodic. In other words, the approximate solution found using the midpoint scheme turns out to be qualitatively similar to the exact one, being rather different quantitatively.
In our opinion, when using the harmonic oscillator model, there is not enough reason to think that the characteristic time scale, taken as physically small, is really small from the point of view of computational mathematics. Therefore, the real reason in favor of using the continuous form of the Newton equations rather than the discrete one is that the traditional method of discretization leads to a violation of the fundamental laws of mechanics (the law of energy conservation) and to a solution, whose properties differ from the expected periodicity. The use of periodic difference schemes removes this difficulty.

A system of coupled oscillators
A system of coupled oscillators can be described as a Hamiltonian system with the Hamiltonian It is assumed that the kinetic and potential energy are described by positively defined quadratic forms.
In the matrix form the system is written as⃗ = − ⃗ . Since the matrices and are symmetric and positively defined, the generalized eigenvalue problem ⃗ = ⃗ yields eigenvectors ⃗ 1 , … , ⃗ that form a basis ℝ , orthonormalized with the weight , corresponding to positive eigenvalues 1 = 2 1 , … , = 2 . In this basis or, due to the basis orthogonality,̈+ 2 = 0, = 1, … , . Each of these equations separately describes the vibration of a harmonic oscillator with the frequency . Therefore, the positive numbers 1 , … , are called eigenfrequencies of the system of coupled oscillators. Now from the formula it is seen that the oscillations of the coupled system will be a superposition of harmonic oscillations at the eigenfrequencies. Now it is important for us that this system has algebraic integralṡ 2 + 2 2 = , which in old variables can be written as Thus, the initial system has quadratic integrals. These integrals will be called partial integrals.

Lemma 3. If the eigenfrequencies are incommensurable, then any algebraic integral of a system of coupled oscillators is expressed algebraically in terms of partial integrals.
The proof of this lemma is somewhat lengthy and is not given here. In essence, it relies on constructions from the proof of Bruns theorem proposed by Painlevé [7].

Remark 2.
The condition of incommensurability of frequencies is essential. If 1 = 2 , then the expressioṅ1 2 − 1̇2 = is an additional algebraic integral. In fact, the general solution of the system is , is really a constant. Thus, without a separate study, it cannot be ruled out that in degenerate cases the system has additional integrals of motion that are not preserved by the midpoint scheme.
According to the theorem 1, the midpoint scheme preserves all partial integrals, and, therefore, all algebraic integrals of the system.
The step Δ can always be chosen so that the normal oscillation at a certain natural frequency is described by a periodic particular solution. However, this step depends on the harmonic number. Therefore, it is impossible to choose a time step at which the oscillation, in the framework of the continuous model, which is a superposition of periodic normal oscillations (mixed oscillation), would be the sum of periodic particular solutions.
Thus, for the case of linear systems of ordinary differential equations, the midpoint scheme is a difference scheme that preserves all algebraic integrals. Moreover, for periodic particular solutions, it is possible to select a step in a purely algebraic way so that the approximate solution becomes periodic in the sense of the definition 2.

Elliptic oscillator
We now proceed to the nonlinear case. Solid state dynamics provides many excellent examples of autonomous systems with periodic solutions. The simplest of them are integrated in Jacobi elliptic functions [8].
This system is convenient for us, because its properties are not only well studied, but the solutions themselves are easily accessible in any computer algebra system, e.g., in Sage [10].
The system (12) is a convenient test for studying the conservatism of finite-difference schemes used in the common numerical solvers of ordinary differential equations. We, in cooperation with Yu.A. Blinkov, conducted tests on the following systems: 1. lsoda: Real-valued Variable-coefficient Ordinary Differential Equation solver, with fixed-leading-coefficient implementation. It provides automatic method switching between implicit Adams method (for non-stiff problems) and a method based on backward differentiation formulas (BDF) (for stiff problems). Source: http://www.netlib.org/odepack; 2. vode: Real-valued Variable-coefficient Ordinary Differential Equation solver, with fixed-leading-coefficient implementation. It provides implicit Adams method (for non-stiff problems) and a method based on backward differentiation formulas (BDF) (for stiff problems). Source: http://www. netlib.org/ode/vode.f; 3. dopri5, dop853: This is an explicit Runge-Kutta method of order (4)5 due to Dormand & Prince (with stepsize control and dense output). In Figures 4-7 it is well seen that in all cases the value of 2 + 2 increases or decreases almost linearly. Only in the first solver (see Figures 2, 3) "random" fluctuations are observed, but with a trend towards linear growth.  From an analytical point of view, this system is remarkable because any particular solution of it is representable as the ratio of two everywhere convergent series in powers of [8]. From the point of view of the finite difference method, this system is remarkable because it can be approximated by a difference scheme, namely, the midpoint scheme (5), which preserves its integrals exactly.  However, for nonlinear differential equations, the organization of the transition from layer to layer according to the midpoint scheme requires solving a system of nonlinear algebraic equations. The organization of calculations according to such a scheme is a subject of discussion.  The midpoint scheme for the system (12) is written as follows:  To pass from one layer to another it is necessary from the given numerical values of Δ and , , to find,̂,, having solved the system of nonlinear equations. In this case, in addition to the required root, close to the values of , , at small Δ , extraneous roots are also obtained. Let us investigate this system in Sage, replacing the hat notation with doubling the letter, e.g., using the notation pp instead of. The system of equations (14) generates an ideal in the ring ℚ[ , , ,,̂,, Δ , ].
Thus, one value of , , on the previous layer generally corresponds to 5 different values of̂rather than one value. Since the higher degrees of̂enter this equation with the factor Δ , for Δ → 0 only one of these roots tends to a finite value, which is obviouslŷ= , and the four others go to infinity. Thus, applying the midpoint scheme to a nonlinear system requires solving a nonlinear equation and then choosing from its roots one root that is 'close' to the values in the previous step.
Traditionally, such equations are solved numerically by iterative methods, and the values of , , are used as the first approximation for,̂,. If the step Δ is sufficiently small, we can expect the fast convergence of the described method. At the same time, it is not possible to control the error of the iterative method due to the extreme cumbersomeness of the known estimates, and instead the number of iterations is simply fixed. However, as correctly noted in Numerical Recipies [12], there are no universal numerical methods for solving systems of algebraic equations.
Symbolic methods, primarily the Gröbner basis technique, allow us to propose a different approach, circumvent this difficulty, and implement calculations according to the midpoint scheme in a different way: -the first stage (symbolic analysis of the finite-difference scheme): find equations having the form (, , , , Δ ) = 0, (̂, , , , Δ ) = 0, (, , , , Δ ) = 0, that follow from Eq. (14); the first of these equations was written out above; -the second stage (computations with floating point): to pass from layer to layer solve three uncoupled equations to find,̂,̂and select the roots close to the values of , , at the previous layer. Thus, from the numerical solution of the system of nonlinear equations, we proceed to the solution of one algebraic equation of the 5th degree with numerical coefficients. The methods of numerical solution are well established and in practice give errors close to the errors in calculating a radical from a number.

Remark 3.
Unfortunately, the algorithms implemented in Sage do not give us, together with the roots, an estimate of this error. The question of the precision solution of algebraic equations with real coefficients is currently discussed at all conferences on numerical methods and computer algebra (MMA'2018, CASC'2019). We hope that in the near future this issue will be completely closed.
We implemented both approaches to the implementation of the midpoint method and made sure that the first approach gives the same result faster. Figures 8-9 show the elliptic sine plot calculated in Sage using the built-in algorithm for calculating elliptic functions and directly using the midpoint method. It is clearly seen that even at extremely large values of , the oscillation amplitude does not decrease. Thus, when using the midpoint scheme: -both algebraic integrals of motion are preserved exactly, -rounding error does not accumulate in a way that is noticeable in numerical experiments, -the periodic nature of the motion is preserved. A theoretical study of the last two issues faces significant difficulties, which, in our opinion, make us search not for any conservative schemes, but for schemes in which the transition from layer to layer requires solving linear equations. One such scheme for the elliptic oscillator (12) was specified by us in [13]; in the general case of the system (1) there are fundamental obstacles to the existence of such schemes [14].

Comparing midpoint scheme with other symmetric schemes
One could think that the conservation of integrals is the result of the scheme symmetry. Therefore, for completeness, we compare the midpoint scheme with another popular symmetric second-order scheme: The results of our numerical experiments, presented in the Figure 10, show that this scheme does not preserve the integrals, but gives them values that oscillate with a constant period around some fixed value. This can be accepted for preserving the integrals of the motion on average.  Figure 10. The value of 2 + 2 − 1, calculated using the scheme (15) This effect can be explained as follows. The scheme (15) for the Jacobi system yields Therefore or, expanding in series in powers of Δ For small Δ in the plot of 2 + 2 versus the step number (or, which is similar, versus ) we will see periodic oscillations of the first term Thus, the oscillation of the value of the integral 2 + 2 near its exact value 1 observed in the numerical experiment is not related to the conservativeness of the scheme, but is due to the fact that the main term in the expansion of the increment of this integral in power of depends on the values of , , , approximating periodic functions. The considered representation scheme is a perfect example of the scheme symmetric with respect to permutation of and.

Conclusion
For the study of dynamical systems with quadratic integrals, the midpoint scheme is perfect. This scheme preserves all the integrals of these systems precisely, that is, discretization does not introduce any dissipativity or antidissipativity into the model. Linear problems have just quadratic integrals, and the calculation according to the midpoint scheme requires solving linear equations, so the issue of constructing conservative difference schemes for linear differential equations can be considered closed. It worth noting that the Kepler problem after passing to proper time and introducing the Runge-Lenz-Laplace vector turns into a linear dynamical system, therefore, it is possible to construct for it a conservative finite-difference scheme [15].
Conservation of integrals leads to the preservation of a number of qualitative properties of the model, e.g., the periodicity of solutions and the closedness of phase trajectories.