<<

Nonlinear Dyn DOI 10.1007/s11071-016-3290-3

ORIGINAL PAPER

A nilpotent algebra approach to Lagrangian mechanics and constrained motion

Aaron D. Schutte

Received: 11 December 2015 / Accepted: 12 December 2016 © Springer Science+Business Media Dordrecht 2016

Abstract Lagrangian mechanics is extended to the Within the Lagrangian framework, one is compelled so-called nilpotent Taylor algebra T. It is shown that to construct the requisite equations of motion of a this extension yields a practical computational tech- mechanical system by first considering the kinemat- nique for the evaluation and analysis of the equations of ics of the system and then by evaluating the total sys- motion of general constrained dynamical systems. The tem kinetic energy T and potential energy U in order underlying T-algebra utilized herein permits the analy- to arrive at the Lagrangian L of the system. Invari- sis of constrained dynamical systems without the need ably, the process requires one to find the partial deriva- for analytical or symbolic differentiations. Instead, the tives of L with respect to (1) the generalized coordi- algebra produces the necessary exact derivatives inher- nates that describe the system state and (2) time. Fur- ently through binary operations, thus permitting the thermore, expressions for U may themselves require numerical analysis of constrained dynamical systems many differentiation evaluations with respect to the using only the defining scalar functions (the Lagrangian system configuration. This process can become non- L and the imposed constraints). The extension of the tractable if a large number of coordinates are involved. Lagrangian framework to the T-algebra is demon- In the presence of constraints, the situation is further strated analytically for a problem of constrained motion complicated since derivative information of the con- in a central field and numerically for the calculation of straints may be needed for both the development of Lyapunov exponents of N-pendulum systems. the constrained equations of motion and their numeri- cal integration. Implementation of analysis techniques Keywords Constrained motion · Automatic involving system linearization and sensitivity calcula- differentiation · Nilpotent algebra · Lagrangian tion of Lagrangian systems also relies on differenti- mechanics · Lyapunov exponents ation and can become quite challenging for complex systems. By extensions of the Lagrangian to the nilpo- tent Taylor algebra developed herein, it is the goal of 1 Introduction this paper to show that the derivation of equations of motion for general constrained dynamical systems and The traditional approach to Lagrangian mechanics their analyses can be transformed from an analytical involves the evaluation of real-valued scalar functions. to a purely numerical process given knowledge of only B the Lagrangian and the constraints on the motion. A. D. Schutte ( ) Schemes for numerical simulation of dynamical sys- The Aerospace Corporation, 2310 E. El Segundo Blvd, El Segundo, CA 90245-4691, USA tems typically rely on formulations wherein the sys- e-mail: [email protected] tem topology is determined before actual implementa- 123 A. D. Schutte tion. This is partly due to the fact that derivatives play structed. It is shown that the Taylor algebra T can be a central role in relating the kinematics of a system used to produce derivatives to arbitrary order of contin- to its dynamics. Practical numerical implementation uous real-valued multivariate functions. The Jacobian of the equations of motion of a constrained dynami- and Hessian numbers are constructed from truncated cal system essentially relies on three different forms T-algebras and used in the description of Lagrangian of differentiation, which include (1) analytical differ- mechanics. More importantly, it is demonstrated how entiation by hand, (2) symbolic differentiation, or (3) the algebras are used to numerically evaluate the ele- automatic differentiation. The first option is feasible if ments needed to formulate general constrained equa- all the necessary derivatives can be obtained by hand tions of motion for dynamical systems and to perform prior to implementation. However, the process must be linearization and sensitivity analyses. Finally, the exact repeated with changing system topology and is error nature of the derivatives produced by the algebras is prone for complex systems. Symbolic differentiation demonstrated analytically for a problem of constrained utilizes a computer algebra system to accomplish the motion in a central field and numerically for the calcu- same feat in a more automated fashion, and as a result lation of Lyapunov exponents for Lagrangian systems. is less error prone. Both of these forms of differenti- ation lead to algorithms that rely on concrete analyti- cal expressions. In contrast, automatic differentiation 2 Nilpotent J, H, and T algebras obtains derivatives of functions numerically. Common automatic differentiation methods apply a judicious Consider a commutative R. By definition, the use of the chain rule to evaluate the derivative of a binary operations of addition (+) and multiplication (·) given function by source code transformation or oper- on R satisfy the usual commutative, associative, and ator overloading [1,2]. This assumes that the function distributive axioms. The element 0 ∈ R is the additive of interest is suitably differentiable and can be imple- identity and 1 ∈ R is the multiplicative identity. While mented in a particular programming language. These all elements in R have an additive inverse, we do not methods fall into the classification of forward or reverse assume multiplicative inverses. Thus, R is not a field. mode techniques, where forward and reverse are used Elements in R that have a multiplicative inverse are to indicate the direction traversed by the chain rule. called units. It is also essential to note that an element k Software implementation of these techniques is widely  ∈ R is nilpotent to order k if  = 0 for minimal + available [3]. Another popular form of numerical dif- k ∈ N . ferentiation includes the complex-step derivative [4– Definition 1 Let R[x1,...,xn] be a polynomial ring 6], which has been used to numerically compute first- over the real numbers in the n algebraically indepen- and second-order derivatives. However, this approach dent indeterminates x1,...,xn. R[x1,...,xn] is called is based on the finite difference approximation and the set of polynomials over the ring R, and it is com- is subject to truncation errors, making it a generally mutative since R is commutative. unfeasible option for the numerical development and analysis of equations of motion for constrained sys- Definition 2 An I is a nonempty subset of the tems. R such that the following closure Yet another approach to automatic differentiation properties are satisfied involves the use of the so-called alge- 1. ∀a, b ∈ I: a ± b ∈ I. bra. The dual numbers, which can be traced back to 2. ∀a ∈ I and ∀b ∈ R: ab ∈ I. the work of Clifford [7], have been shown to produce exact first derivatives of real-valued functions by sim- An ideal allows the construction of a R/I ply extending the function to the dual number alge- (also written as R mod I). This is essentially a new bra. In mechanics, dual numbers have been primarily ring with the elements of the ideal I removed from used in kinematics analysis; e.g., see [8]. A dual num- the ring R. The quotient of a polynomial ring in mul- ber extension to second-order derivatives has recently tiple indeterminates is given by R[x1,...,xn]/I.This been developed [9], which was successfully applied to is an important type of ring since many rings are con- a Navier–Stokes solver. In what follows, a superset of veniently expressed as a quotient of polynomial rings. the dual numbers called the Taylor numbers is con- Here, it is assumed the ideal I = (α1,...,αm) is a 123 A nilpotent algebra approach to Lagrangian mechanics and constrained motion set of generators such that αi ∈ R[x1,...,xn].This Clearly, Eq. (7) represents a first degree Taylor polyno- allows the construction of the Taylor algebra mial. Higher degree terms vanish since higher powers of  are zero. Thus, f˜(z) returns the evaluated function T(1,...,n)  R[x1,...,xn]  f (a0) and information about the first derivative f (a0). /{x x ···x } , , ∈N+ , (1)  i j m i j m The exact derivative f (a0) is obtained by evaluating f˜(a + ). This is one of the most useful properties of where the ideal I ={xi x j ···xm}i, j,m∈N+ is both max- 0 imal and nilpotent to order m for 1 ≤ i, j,...,m ≤ n. the Jacobian algebra. An ideal is nilpotent when Ik ={0} for any k ∈ N+. Extending the Jacobian algebra to higher derivatives T Note that the T-algebra actually depends on the trun- yields another subset of a truncated –algebra, which  3 = cation order m. Obscurely, the most germane and inter- has a third-order nilpotent element such that 0.  H esting property of this algebra lies in its ability to pro- In a single indeterminate , the Hessian algebra, ,is duce exact derivatives to arbitrary order of continuous given in the single indeterminate form as real-valued multivariate functions. This can be accom- H()  R[x]/{x3}. (8) plished by simply extending the function of interest to The Hessian number is given by the T–algebra of appropriate truncation order. = +  + 2, The dual numbers are a well-known subset of a z a0 a1 a2 (9) truncated T–algebra. Abstractly, the dual numbers are where a0, a1, a2 ∈ R. Addition and multiplication of derived from the Jacobian algebra, J, in a single inde- the Hessian number follow the definitions terminate  so that (a0, a1, a2) + (b0, b1, b2) J()  [ ]/{ 2}; R x x (2) = (a0 + b0, a1 + b1, a2 + b2) (10) i.e., J() is isomorphic to the quotient ring R[x]/{x2}. and

They are commonly written in the form (a0, a1, a2) · (b0, b1, b2) = ( , + , + + ). z = a0 + a1, (3) a0b0 a0b1 b0a1 a0b2 b0a2 a1b1 (11) : R → where a , a ∈ R. Thus, the dual number is a type An extension of the sufficiently smooth map f 0 1 R ˜ : H → H of Jacobian number. Namely, a Jacobian number with to the map f then yields a single indeterminate . The Jacobian number z in ˜( ) = ˜( +  + 2) = ( ) + ( )  f z f a0 a1 a2 f a0 f a0 a1 ( , )  Eq. (3) is then a particular 2-vector a0 a1 over the  f (a ) + f (a )a + 0 a2 2. (12) real numbers, where multiplication must follow the rule 0 2 2! 1 k = k ∈{ , ,...} 0for 2 3 . Addition and multiplication In order to extract the first and second derivatives of f , of the Jacobian numbers are defined by it is apparent from Eq. (12) that one should evaluate the ˜( + ) (a0, a1) + (b0, b1) = (a0 + b0, a1 + b1), (4) Hessian function f a0 and multiply the resulting 2 element by a factor of 2. and Generalizing  to higher powers, the construction of (a0, a1) · (b0, b1) = (a0b0, a0b1 + b0a1). (5) the more general Taylor algebra in single indeterminate form is given as Division of two Jacobian numbers is determined by   T()  R[x]/{xn}. (13) b + b  a − a  b b a − b a 0 1 · 0 1 = 0 , 1 0 0 1 . (6) The Taylor number is simply +  −  2 a0 a1 a0 a1 a0 a0 2 n T z = a0 + a1 + a2 +···+an = a0 + a E, Using Eq. (6), it can be verified that the Jacobian num- (14) ber a + a  is a for all nonzero a . The utility of 0 1 0 ∈ R ∈ Rn =[, 2,...,n]T the Jacobian number becomes obvious when we con- where a0 , a , E , and n+1 = sider the extension of the map f : R → R to the map 0. The basic operations of addition and multi- plication of Taylor numbers are defined by the tuples f˜ : J → J. For sufficiently smooth functions f ,this   T T T T leads to the following evaluation (a0, a E) + (b0, b E) = a0 + b0,(a + b )E ˜ ˜  f (z) = f (a0 + a1) = f (a0) + f (a0)a1. (7) (15) 123 A. D. Schutte and where Bi is the i-th 1 by n row matrix of B.By T T extending the sufficiently smooth vector-valued func- (a0, a E) · (b0, b E)    tion f : Rn → Rm to the map f˜ : Hn → Hm we = , T + T , T T . a0b0 a0b b0a E a EE b (16) therefore obtain ⎡ ⎤ 1 In Eq. (16), it can be shown that T ( ) ⎡ ⎤ ⎢ H f1 a ⎥ 2 3 4 ··· n 0 ⎢ 2! ⎥ ˜ ⎢ . ⎥ ⎢ . . . ⎥ f (z) = f (a) + J f (a) + ⎢ . ⎥ , (23) ⎢ 3 . . n . . . ⎥ ⎣ ⎦ ⎢ ⎥ 1 ⎢ . . . ⎥ T H f (a) ⎢ 4 . . . . . ⎥ ! m T ⎢  . ⎥ 2 EE = ⎢ . . ⎥ . (17) ⎢ . . . . ⎥ where z is evaluated at B = I and C = 0fori = ⎢ .n . . ⎥ n i ⎢ ⎥ 1,...,n. Thus, the function f˜(z) in Eq. (23) yields ⎣ . . . ⎦ n . . (in a single function evaluation) the real-valued vector 0 ··· ··· ··· ··· 0 function f (a), the real-valued Jacobian J f (a), and the ( ),..., ( ) Once again, for sufficiently smooth real-valued func- real-valued Hessians H f1 a H fm a . tions f : R → R,themap f˜ : T → T is generalized to an nth-order Taylor series expansion in  as 3 Lagrangian mechanics over the Hessian ˜( ) = ˜( + T ) = ( ) f z f a0 a E f a0 numbers n   f (k)(a ) k + 0 aT E , (18) k! Consider a mechanical system with kinetic energy k=1 T (q, q˙, t) and potential energy U(q). The Lagrangian  k where aT E is the kth-order piece in . Consequently, of the system is given by the scalar function L(q, q˙, t) = the k-th derivative of f is recovered by evaluating T (q, q˙, t) − U(q), where q, q˙ ∈ Rn are the general- ˜ k f (a0 + ) and then by multiplying the  element by a ized position and velocity vectors and t ∈[0, ∞) is factor of k!. the time. Assuming the components of the generalized In multiple indeterminates, the Hessian algebra is coordinate vector q are independent from one another, given by the Lagrange equations are most often applied using

H(1,...,n)  R[x1,...,xn]/(xi x j xk), the component form ≤ , , ≤ . d ∂ L ∂ L 1 i j k n (19) − = Γ , i = ,...,n, ∂ ˙ ∂ i 1 (24) This algebra has great practical applicability in prob- dt qi qi : Rn → Rm T lems involving multivariate functions f . where the n-vector Γ = (Γ1,...,Γn) is an arbitrary For example, consider z ∈ Hn of the form ⎡ ⎤ generalized force vector and n is the number of general- T  C1 ized coordinates. Departing from the standard compo- ⎢ . ⎥ nent form, the Newtonian form of Eq. (24)isrecovered z = a + B + ⎣ . ⎦ , (20) by considering the differential of L ˙ = ∂ L/∂q˙ as T q  Cn ∂ Lq˙ ∂ Lq˙ ∂ Lq˙  =[ ,..., ]T ∈ Rn ∈ Rn×n ∈ dL ˙ = dq + dq˙ + dt. (25) where 1 n , a , B , and Ci q ∂q ∂q˙ ∂t Rn×n for i = 1,...,n. Addition and multiplication of L two elements of the vector z ∈ Hn are defined as By taking the differential d q˙ with respect to time, the matrix-vector representation of Lagrange’s equation of + = + + ( + ) + T( + ) z1 z2 a1 a2 B1 B2 C1 C2 motion is (21) ∂2L ∂2L ∂2L ∂ L M(q, t)q¨ := q¨ = Γ − q˙ − + and ∂q˙2 ∂q∂q˙ ∂t∂q˙ ∂q := ( , ˙, ), · = + ( + ) Q q q t (26) z1 z2 a1a2  a1 B2 a2 B1  1 1 where M ∈ Rn×n and Q ∈ Rn. Equation (26) describes + T a C + a C + BT B + BT B , 1 2 2 1 2 1 2 2 2 1 the unconstrained motion of the system, wherein the (22) terminology ’unconstrained’ is used to imply that the n 123 A nilpotent algebra approach to Lagrangian mechanics and constrained motion generalized coordinates q are to be treated as indepen- where A is a matrix with m = s1 + s2 rows and n dent of one another. The motion of the unconstrained columns and b is an m-vector. We note that the set of system described by Eq. (26) can be uniquely deter- constraints in Eq. (30) should be consistent (AA+b = mined at time t since M > 0, and assuming the initial b), while the rows of A may be linearly dependent. T position q(0) = q0 and velocity q˙(0) =˙q0 are pro- If the matrix [MA] has full rank, then the auxiliary vided at initial time t0. mass matrix When the system is subjected to constraints, an addi- M = M + ATWA> 0 (31) tional force of constraint, Qc(q, q˙, t), arises such that is positive definite with positive definite diagonal ¨ = + . Mq Q Qc (27) weighting matrix

Additionally, the mass matrix may only be positive W = diag(w1,...,wm)>0. semi-definite (M ≥ 0) and non-invertible if Lagrange’s The weights w ,...,w simply scale the m-constraints equation is applied with dependent generalized coordi- 1 m relative to the mass matrix M. Under the condition nates. The constraints may have the form given by Eq. (31), the constrained equations of motion φi (q, t) = 0 i = 1,...,s1, (28) can then become [10–12] T −1 T + −1 and Mq¨ = Q + A (AM A ) (b − AM Q), (32) where the superscript + symbol denotes the Moore- ψi (q, q˙, t) = 0 i = 1,...,s2, (29) Penrose matrix inverse. which constitutes a general set of holonomic and non- Obtaining closed-form expressions of the con- holonomic bilateral constraints, respectively. The ini- strained equations of motion depends on the determi- ˙ tial conditions q0 and q0 are now assumed to satisfy the nation of four elements. Namely, the mass matrix M, constraints in Eqs. (28) and (29) at initial time t0.The the generalized force vector Q, the constraint matrix A, force of constraint Qc must be devised to ensure that and the constraint vector b. In comparison with other these constraints are satisfied at each instant in time. formulations [13], Eq. (32) does not require the use of Assuming the constraints in Eqs. (28) and (29)are Lagrange multipliers, which will eventually simplify continuously differentiable with respect to time, they the Lagrangian evaluations in what follows. It is evi- can take the form of the constraint matrix equation ⎡ ⎤ dent from the expressions above that M, Q, A, and b are L φ ∂φ1 constructed using only the partial derivatives of , , ⎢ ∂q ⎥ ψ ˙ ⎢ ⎥ and with respect to q, q, and t. Normally, one would ⎢ . ⎥ ⎢ . ⎥ derive these expressions and evaluate the derivatives in ⎢ ∂φ ⎥ ⎢ s1 ⎥ closed-form before arriving at the required equations ⎢ ∂q ⎥ of motion. Here, we show that these objects can also Aq¨ := ⎢ ∂ψ ⎥ q¨ ⎢ 1 ⎥ be obtained by extending the real-valued Lagrangian ⎢ ∂q˙ ⎥ ⎢ ⎥ L : Rn × Rn × R → R ⎢ . ⎥ map to the Hessian-valued ⎢ . ⎥ ˜ n n ⎣ ⎦ H(1,...,n) Lagrangian map L : H ×H ×H → H, ∂ψ + s2 or equivalently L˜ : H2n 1 → H. ∂q˙ ⎡ ⎤ Define a generalized state vector z ∈ H2n+1 so that ∂2φ ∂2φ ∂2φ ⎡ ⎤ −˙qT 1 q˙ − 2 1 q˙ − 1 ⎡ ⎤ ⎡ ⎤ T ⎢ ∂ 2 ∂t∂q ∂ 2 ⎥  C1 ⎢ q t ⎥ zq q ⎢ ⎥ ⎢ . ⎥ = ⎣ ⎦ = ⎣ ˙ ⎦ +  + . , ⎢ . ⎥ z zq˙ q B ⎣ . ⎦ (33) ⎢ ⎥ z t T ⎢ ∂2φ ∂2φ ∂2φ ⎥ t  C2n+1 ⎢ −˙T s1 ˙ − s1 ˙ − s1 ⎥ ⎢ q 2 q 2 ∂ ∂ q 2 ⎥ = ⎢ ∂q t q ∂t ⎥ := b, where ⎢ ∂ψ ∂ψ ⎥ ⎢ − 1 q˙ − 1 ⎥ T T T T ⎢ ∂q ∂t ⎥  =[ ,˙ ,t ] =[q ,...,q ,q˙ ,...,q˙ ,t ] , ⎢ . ⎥ q q 1 n 1 n ⎢ . ⎥ 2n+1×2n+1 ⎣ . ⎦ B ∈ R , ∂ψ ∂ψ − s2 ˙ − s2 ∂q q ∂t and 2n+1×2n+1 (30) Ci ∈ R , i = 1,...,2n + 1. 123 A. D. Schutte

Given the Lagrangian of the system L(q, q˙, t),the yields   extended Hessian-valued Lagrangian is then given by ∂ψ ∂ψ ∂ψ ˜ ˜ ψ˜ ( ∗) = ψ + i i i . L(z). At each instant in time, we can evaluate L(z) at i z i ∂q ∂q˙ ∂t (39) z = z∗, where ⎡ ⎤ Equations (37) and (39) then contain all the elements ∗ q + q needed to construct the constraint matrix A and the ∗ ⎣ ∗ ⎦ ∗ ∗ z = q˙ + q˙ (34) constraint vector b evaluated at q = q , q˙ =˙q , and ∗ ∗ t + t t = t . Observe that the constrained Lagrange equa- tions of motion given by Eq. (32) can then be obtained is obtained using the values B = In and Ci = 0for i = 1,...,2n + 1. This yields by pure numerical evaluation of the extended functions   L˜(z∗), φ(˜ z∗), and ψ(˜ z∗)! ˜ ∗ ∂ L ∂ L ∂ L L(z ) = L + ∂ ∂ ˙ ∂  + ⎡ q q t ⎤ ∂2L ∂2L ∂2L ⎢ 2 ∂ ˙∂ ∂ ∂ ⎥ 4 Numerical linearization of Lagrangian systems ⎢ ∂q q q t q ⎥ 1 ⎢ ∂2L ∂2L ∂2L ⎥ T ⎢ ⎥ . (35) ! ⎢ ∂q∂q˙ ∂ ˙2 ∂t∂q˙ ⎥ Given the exact nature of the derivatives produced by 2 ⎣ q ⎦ ∂2L ∂2L ∂2L the T-algebras, analyses requiring system lineariza- ∂q∂t ∂q˙∂t ∂t2 tion or sensitivity calculation are easily carried out numerically without truncation error using extended The Hessian-valued Lagrangian map L˜(z∗) consists of Lagrangian L˜(z∗) evaluations. Consider a Lagrangian (1) the Lagrangian function evaluation, (2) the gradient system with configuration expressible as a bijective of the Lagrangian, and (3) the Hessian matrix of the function of the minimum number of generalized coor- Lagrangian with respect to q, q˙, and t; each evaluated dinates at q = q∗, q˙ =˙q∗, and t = t∗. The elements needed to construct the unconstrained equations of motion of υ = υ(q), (40) the system are obtained directly from Eq. (35)asis where υ ∈ Rn are the reference coordinates and q ∈ Rn apparent in Eq. (26); i.e., Eq. (35) produces the mass are the generalized coordinates. The acceleration of the matrix M and the generalized force vector Q evaluated system (Eq. (32)) is given as at q = q∗, q˙ =˙q∗, and t = t∗.  −   When constraints are imposed, the holonomic con- ∂2L 1 ∂2L ∂ L −1 straints, φ(q, t), and the nonholonomic constraints, q¨ = M Q = Γ − q˙ + ∂q˙2 ∂q∂q˙ ∂q ψ(˙ q, q˙, t), require second- and first-order derivative information, respectively, as shown in Eq. (30). For (41) n+1 ˜ z ∈ H ,thei-th Hessian-valued constraint φi (z) since no constraints are imposed on the motion. Differ- evaluated at   entiating Eq. (40) once with respect to time yields ∗ +  ∗ = q q ∂υ z ∗ +  (36) υ˙ = q˙ := Φ(q)q˙, (42) t t ∂q yields Φ ∈ Rn×n   where is nonsingular. A second differentia- ∂φ ∂φ φ˜ ( ∗) = φ + i i  tion with respect to time yields i z i ∂q ∂t ⎡ ⎤ ˙ 2 2 υ¨ = Φq˙ + Φq¨. (43) ∂ φi ∂ φi 1 ⎢ ∂ 2 ∂t∂q ⎥ + T ⎣ q ⎦ . (37) Substitution of Eq. (41) into Eq. (43) yields the accel- ! ∂2φ ∂2φ 2 i i eration of the reference coordinates as a function of the ∂q∂t 2 ∂t generalized coordinates q and q˙ as 2n+1 For z ∈ J ,thei-th Jacobian-valued constraint ˙ −1 ˜ υ¨ = Φq˙ + Φ M Q. (44) ψi (z) evaluated at ⎡ ⎤ ∗ +  A first-order realization of Eq. (44) is given by q q     ∗ ⎣ ∗ ⎦ z = q˙ + q˙ (38) x˙1 x2 ∗ x˙ := = , (45) t + t x˙2 υ¨ 123 A nilpotent algebra approach to Lagrangian mechanics and constrained motion

= υ =˙υ =[ T, T]T where x1 , x2 , and x x1 x2 . Note that 5 Implementation and application the acceleration υ¨ in Eq. (45) is obtained directly from Eq. (44). Actual computational implementation of a particular Ignoring any input or output relations for simplicity, truncated T-algebra can be accomplished in software a linear model of Eq. (45) is obtained by considering using object-oriented programming techniques such the perturbation δ ∈ R2n about the operating point as operator overloading. A class structure can be cre- 2n x0 ∈ R such that x = x0 + δ. The linearization with ated that encapsulates the appropriate T-algebra num- minimum-sized Jacobian, A, is then given by ber. For example, the class data definition of an H()-    algebra would include three distinct floating-point dec- 0In  2 δ˙ = ∂ ˙ ∂ ∂ ˙ ∂ ˙ ∂ ˙ ∂ ˙  larations that represent the scalar, , and  parts. The x2 q + x2 q x2 q  = ∂ ∂ ∂ ˙ ∂ ∂ ˙ ∂ x x0 methods of the class are then defined to override the q x1 q x1 q x2 q=q0 q˙=˙q0 binary operations and special functions. In particular, δ := Aδ, (46) the binary operators of addition (+) and multiplication ∂ ∂ (*)oftwoH() numbers would be coded to follow q = q = ( , ˙ ) where ∂ ∂υ˙ 0 and q0 q0 is the operating x2 the relations in Eqs. (10) and (11), while the special point in terms of the generalized coordinates. Clearly, functions such as sin(z) would be coded to follow the the linearization in Eq. (46) requires (1) the inverse evaluation in Eq. (12)as function of Eq. (40) sin(z) = sin(a + b + c2) = sin(a) + b cos(a) q = q(υ) (47)   2 b 2 −1 + c cos(a) − sin(a)  . (50) and (2) the differentiation of the matrices M and Q 2 with respect to q and q˙. If the quantities M and Q are known analytically, one could theoretically compute A In hardware, a field programmable gate array (FPGA) analytically by using the formula coprocessor could theoretically be designed to imple- − − − ment a particular T-algebra natively. A typical micro- dM 1 =−M 1dMM 1. (48) processor (CPU) could then offload numerical deriva- For complex Lagrangians L, this process is formidable tive computations to the FPGA in parallel. and most likely not possible. However, numerical cal- Once an appropriately truncated T-algebra has been culation of these objects using the T-algebra is triv- implemented computationally, it is quite trivial to ial. For example, using Eq. (48), the derivative of the functionally evaluate the extended Lagrangian and −1 inverse mass matrix M with respect to qi in terms of motion constraints. The function evaluation using the the Lagrangian L is given by T-algebra implementation provides all the derivatives needed for the formulation of constrained equations ∂ M−1 ∂ M =−M−1 M−1 of motion and their linearization as demonstrated in ∂q ∂q i  i   Sects.3 and 4. This also simplifies sensitivity analyses −1 −1 ∂2L ∂3L ∂2L with respect to many system parameters. On the con- =− . 2 2 2 (49) trary, using analytical derivatives for sensitivity analy- ∂q˙ ∂qi ∂q˙ ∂q˙ ses with respect to arbitrary system parameters is quite Since the second relation in Eq. (49) requires third- difficult, or impossible, for complex systems. order derivatives, it is apparent that Eq. (49) can be cal- In the following, two simple yet fairly compre- culated numerically by extending the Lagrangian L to a hensive examples are provided to demonstrate how third-order truncated T-algebra (see Sect.2) evaluation. the extended Lagrangian and constraint functions can In this way, the linearization in Eq. (46) can also be cal- yield the derivatives needed to construct the constrained culated numerically and directly from the Lagrangian equations of motion of a Lagrangian system in terms of L. Once the T-algebra has been implemented compu- the matrices M, Q, A, and b, and for the computation tationally, it inheres the burden of derivative computa- of Lyapunov exponents for a given Lagrangian system. tion, and the linearization is easily obtained once the Increasingly complex examples can obviously be han- Lagrangian L and the desired minimum coordinate rep- dled simply by deriving the appropriate Lagrangian and resentation υ(q) and its inverse are defined. the required constraints. 123 A. D. Schutte

described in Sect.3. This is accomplished by extend- ing the Lagrangian L(q, q˙) → L˜(z) and the constraint φ(q) → φ(˜ z). The Hessian state vector z ∈ H8 is given as ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ zr r TC  ⎢ ⎥ ⎢ ˆ ⎥ 1 ⎢ zrˆ ⎥ ⎢ r ⎥ ⎢ . ⎥ z = ⎣ ⎦ = ⎣ ⎦ + B + ⎣ . ⎦ , (57) zr˙ r˙ T ˆ˙  C8 zrˆ˙ r T T T T where  =[r , ,r˙, ] =[1,...,8] , B ∈ rˆ rˆ˙ 8×8 8×8 R , and Ci ∈ R for i = 1,...,8. Thus, we can evaluate Fig. 1 A particle moving in a central field  μ L˜( ) = 1 2 + 2 T + m z m zr˙ zr zˆ˙ zrˆ˙ (58) 2 r zr 5.1 Illustrative example: constrained motion in a at z = z∗, where central field ⎡ ⎤ r + r ⎢ ˆ +  ⎥ ∗ ⎢ r rˆ ⎥ Consider a single particle with mass m moving relative z = ⎣ ⎦ . (59) r˙ + r˙ to an inertial frame of reference FN with orthonormal ˙ rˆ + ˙ basis. The position of the particle in the inertial frame rˆ is given by the 3-vector r. As illustrated in Fig. 1,the By appropriately carrying out the Hessian-based binary position vector, r, can be decomposed into magnitude operations, we obtain and normalized vector form by 2 =˙2 + ˙ + 2, zr˙ r 2r r˙ r˙ (60) 2 T 2 ˙T ˙ ˙T ˙ 2 ˙T ˙T ˙ 2 r = rrˆ, (51) z z z˙ = r rˆ rˆ + 2rrˆ rˆ + 2r rˆ ˙ + rˆ rˆ r rˆ˙ rˆ r rˆ r where rˆ is a unit 3-vector and r is the magnitude of + ˆ˙T  + 2T , 4rr r rˆ˙ r ˆ˙ rˆ˙ (61) the position vector r. The position of the particle is r and therefore defined by four coordinates from which three 1 1 1 1 of the coordinates are constrained by the relation = −  + 2. 2 r 3 r (62) zr r r r φ(q) = rˆTrˆ − 1 = 0, (52) Combining like terms in ,Eq.(58) then yields where q =[r, rˆT]T is the generalized coordinate 4-  μ L˜( ∗) = 1 ˙2 + 2 ˆ˙T ˆ˙ + m + vector describing the configuration of the system. The z m r r r r 2  r  velocity of the particle is given by ˙ ˙ μm ˙   + mrrˆTrˆ − 0 mrmr˙ 2rˆ  ∂   ˙ r 2 r r ⎡ μ ⎤ r˙ = q˙ := rˆ rI3 ˙ . (53) ˙T ˙ m ˙ ∂q rˆ mrˆ rˆ + 2 002mrrˆT ⎢ r 3 ⎥ 1 ⎢ ⎥ The kinetic energy is subsequently derived as + T ⎢ 0000⎥ .(63)  2 ⎣ 00m 0 ⎦ 1 1 ˙ ˙ T (q, q˙) = mr˙Tr˙ = m r˙2 + r 2rˆTrˆ . (54) ˆ˙ 2 2 2 2mrr 00 mr I3 Furthermore, we assume the particle is moving in a Similarly, the evaluation of uniform gravitational field so that we have the potential ˜ T φ(z) = zˆ zrˆ − 1(64) μm r U(q) =− , (55) at z = z∗ for r   +  where μ>0. This yields the Lagrangian ∗ = r r z ˆ +  (65)  μ r rˆ L( , ˙) = 1 ˙2 + 2 ˆ˙T ˆ˙ + m . q q m r r r r (56) yields 2 r     To evaluate the constrained equations of motion, ∗ 1 00 φ(˜ z ) = rˆTrˆ − 1 + 02rˆT  + T . (66) we need to obtain the elements M, Q, A, and b as 2 02I3 123 A nilpotent algebra approach to Lagrangian mechanics and constrained motion

In regard to the constrained equations of motion of the system, Eqs. (63) and (66) contain all the needed infor- mation. The mass matrix is   = m 0 , M 2 (67) 0 mr I3 the generalized force vector is ⎡ ⎤ μm mrrˆ˙Trˆ˙ − Q = ⎣ r 2 ⎦ , (68) ˙ −2mrr˙rˆ the constraint matrix is   A = 02rˆT , (69) and the constraint vector (a 1-vector here) is ˙ ˙ b =−2rˆTrˆ. (70) Given a constraint weight w>0, we can compile these elements into Eq. (32) to obtain the constrained accel- Fig. 2 AplanarN-pendulum system eration of the system as ⎡  ⎤   μ r rˆ˙Trˆ˙ − where mi is the i-th eigenvalue of Y . The largest Lya- r¨ 2 = ⎣  r ⎦ . (71) punov exponent (usually of most interest) is termed the ¨ˆ 2r˙ ˙ ˙ ˙ r − rˆ − rˆTrˆ rˆ maximal Lyapunov exponent (MLE). Computation of r the n Lyapunov exponents of Eq. (72) can be accom- Equation (71) is provided analytically for completeness plished by solving the initial value problem [14] with the understanding that we could also produce this ˙ = ( ), ( ) = equation at any given instant in time using only the y f y y 0 y0 (75) L˜( ∗) φ(˜ ∗) Q˙ = Q , Q( ) = , numerical calculations z and z .  S 0 In (76) ∂ f ρ˙ = QT Q ,ρ( ) = , i = ,...,n, i ∂ i 0 0 1 5.2 Numerical example: Lyapunov exponents of y i,i N-pendulum systems (77) where the n by n matrix Q is the orthogonal matrix Lyapunov exponents are quantities used to characterize obtained from the QR–decomposition the asymptotic behavior of a dynamical system. They = Q are commonly used to determine whether the system Y R (78) is sensitive to initial conditions and to help establish and the n by n matrix S is defined as ⎧  chaos. Given an autonomous dynamical system ⎪ ∂ f ⎪ QT Q , i > j ˙ = ( ), ∈ Rn, : Rn → Rn, ⎪ ∂ y f y y f (72) ⎨ y i, j S = 0, i = j . (79) the variational equation ⎪   ⎪ ∂ f ∂ ⎩⎪− QT Q , i < j ˙ f n×n ∂ Y = Y, Y ∈ R , (73) y j,i ∂y The time evolution of the Lyapunov exponent spectrum can be used to compute the Lyapunov exponents of the is then given by system in Eq. (72). The spectrum of Lyapunov expo- ρ (t) nents of Eq. (72) are defined as λ (t) = i , i = 1,...,n, (80) i t 1 λi = lim ln(|mi |), i = 1,...,n, (74) and the value of each Lyapunov exponent is given by t→∞ t λi = lim λi (t), i = 1,...,n. (81) t→∞ 123 A. D. Schutte

Fig. 3 Time evolution of the N-pendulum MLE

Now consider the MLE calculation of the planar N- where the i-th column of ∂q¨/∂q is       pendulum system illustrated in Fig. 2, where the Lya- −1 −1 ∂q¨ ∂2L ∂3L ∂2L ∂ L ∂2L punov exponent spectrum is 2N dimensional. The cal- =− − q˙ ∂ ∂ ˙2 ∂ ∂ ˙2 ∂ ˙2 ∂ ∂ ∂ ˙ culation of the MLE clearly depends on the realizations qi q qi q q q q q     −1 of the n-vector f (y) and the n by n matrix ∂ f/∂y, where ∂2L ∂2L ∂3L + − ˙ the state vector is given by 2 q (88) ∂q˙ ∂qi ∂q ∂qi ∂q∂q˙ = ( , ˙) = (θ ,...,θ , θ˙ ,...,θ˙ ), ∈ R2N . y q q 1 N 1 N y and the i-th column of ∂q¨/∂q˙ is       (82) −1 −1 ∂q¨ ∂2L ∂3L ∂2L ∂ L ∂2L =− − q˙ 2 2 2 For the N-pendulum system in Fig.2, f is obtained ∂q˙i ∂q˙ ∂q˙i ∂q˙ ∂q˙ ∂q ∂q∂q˙     from Eq. (26)as −1     ∂2L ∂2L ∂3L ∂2L ∂q˙ + − q˙ − q˙ q˙ 2 ∂ ˙ ∂ ∂ ˙ ∂ ∂ ˙ ∂ ∂ ˙ ∂ ˙ f = = ∂q˙ qi q qi q q q q qi q¨ M−1 Q ⎡ ⎤ (89) ˙    q  ⎣ −1 ⎦ All of the derivatives in Eqs. (83), (88), and (89)are = ∂2L ∂ L ∂2L (83) − q˙ obtained numerically using a third-order nilpotent alge- ∂ ˙2 ∂q ∂q∂q˙ q bra as described in Sect.2. This eliminates the need since no constraints are present and L has no explicit to re-derive analytical expressions as N (the number dependence on time; i.e., of pendulums) increases. The numerical evaluation of L(z∗) is all that is needed. N N 1 A Fortran 2008 module that implements the third- L = m r˙i ·˙ri − mg hi , (84) 2 order multivariate nilpotent algebra was constructed to i=1 i=1 enable numerical calculation of Eqs. (83), (88), and > where for i 1 (89). A simulation that implements Eqs. (75)–(77) ˙ T N r˙i =˙ri−1 + lθi [cos θi , − sin θi ] (85) using numerical derivatives for the pendulum sys- tem was then constructed. As N increases, the initial and conditions were chosen as   ( ) = θ ,θ ,...,θ T = ◦, ,..., T hi = hi−1 − l cos θi . (86) q 0 [ 1 2 N ] 75 0 0 (90) The matrix ∂ f/∂y is then given by and ⎡ ⎤ ˙ ˙ ˙ T T q˙(0) =[θ1, θ2,...,θN ] =[0, 0,...,0] . (91) ∂ f 0IN = ⎣∂q¨ ∂q¨ ⎦ , (87) The mass and length of each pendulum is chosen as ∂y ∂q ∂q˙ m = 1 and l = 1, and the gravitational constant 123 A nilpotent algebra approach to Lagrangian mechanics and constrained motion

Table 1 Approximate N λ matrix Q. Since the system is conservative, the total maximal Lyapunov MLE energy of the system exponent with increasing N 13× 10−5 N N 20.1 1 E = m r˙i ·˙ri + mg hi (92) 30.8 2 i=1 i=1 41.4 52.2should not deviate from the initial value E0 throughout the system trajectory. The growth in the errors shown in 63.1 Figs. 4 and 5 indicates that a variable time step and/or g = 9.81. Using a fixed-step fifth-order Dormand- higher-order integrator may be needed for improved Prince integration scheme with step size of 0.05 sec- accuracy with increasing N. It is important to note that onds, the time history of the resulting MLE for each sys- the entire analysis was completed without analytically tem (up to N = 6) is shown in Fig. 3. Approximate val- differentiating any expressions. Only the Lagrangian in ues of λMLE for each system are reported in Table 1.As Eq. (84) was needed. expected, λMLE approaches zero when N = 1, which is consistent with the fact that the system is conserva- tive and two dimensional. The other higher-order cases 6 Conclusions show increasingly positive λMLE values. Finally, Figs.4 and 5 illustrate the evolution of the errors in the energy In this paper, a nilpotent algebra approach is developed conservation of the system and the orthogonality of the for comprehensive numerical analysis of constrained

Fig. 4 Time evolution of the error in total energy conservation |E − E0|

Fig. 5 Time evolution of the maximum component of |QTQ − I |

123 A. D. Schutte dynamical systems in the Lagrangian framework. 3. Griewank, A., Juedes, D., Utke, J.: Algorithm 755: ADOL- This was accomplished by extending the Lagrangian C: a package for the automatic differentiation of algorithms L(q, q˙, t) and the constraints φ(q, t) and ψ(q, q˙, t) to written in C/C++. ACM Trans. Math. Softw. 22, 131167 T (1996) truncated -algebras (multivariate generalizations of 4. Lyness, J.N., Moler, C.B.: Numerical differentiation of ana- the so-called dual number algebra). Conceptually, it lytic functions. J. Numer. Anal. 4, 202210 (1967) was shown that the process for numerical derivation of 5. Kroo, J.R.R.A., Alonso, J.J.: An Automated Method for constrained equations of motion can be quite simple Sensitivity Analysis Using Complex Variables. American Institute of Aeronautics and Astronautics, Reston (2000). since only four elements are needed, namely the mass AIAA-2000-0689 matrix M, the generalized force vector Q, the constraint 6. Lai, K.L., Crassidis, J.L.: Extensions of the first and second matrix A, and the constraint vector b. It was shown that complex-step derivative approximations. J. Comput. Appl. these elements can be constructed numerically by eval- Math. 219, 276293 (2008) L˜( ) φ(˜ ) ψ(˜ ) 7. Clifford, W.K.: Preliminary sketch of . Proc. uating the extended z , z , and z functions with Lond. Math. Soc. 4, 381–395 (1873) + a generalized state vector z ∈ H2n 1. In addition, it was 8. Veldkamp, G.R.: On the use of dual numbers, vectors, and shown that exact numerical linearization and sensitiv- matrices in instantaneous, spatial kinematics. Mech. Mach. ity calculations can be carried out directly by extending Theory 11, 141–156 (1976) T 9. Fike, J.A., Alonso, J.J.: Automatic differentiation through the Lagrangian to a third-order truncated -algebra, the use of hyper-dual numbers for second derivatives. which was demonstrated numerically for the compu- Lecture notes in Computational Science and Engineering: tation of Lyapunov exponents in N-pendulum sys- Recent Advances in Algorithmic Differentiation, vol. 87, tems. The approach eliminates the need to obtain ana- pp. 163–173 (2012) 10. Udwadia, F.E., Schutte, A.D.: Equations of motion for gen- lytical derivatives prior to computational implemen- eral constrained systems in lagrangian mechanics. Acta tation. This is a significant capability when consider- Mech. 213, 111–129 (2010) ing algorithm development for analysis of Lagrangian 11. Udwadia, F.E., Schutte, A.D.: A unified approach to rigid systems in general, especially for systems with com- body rotational dynamics and control. Proc. Roy. Soc. A 468, 395–414 (2012) plex Lagrangians and many interacting subsystems. In 12. Udwadia, F.E., Wanichanon, T.: On general nonlinear practice, these algebras can be implemented in soft- constrained mechanical systems. Numer. Algebra Control ware using standard operator overloading techniques, Optim. 3(3), 425–443 (2013) or in hardware using Hardware Description Language 13. Bayo, E., Ledesma, R.: Augmented lagrangian and mass- orthogonal projection methods for constrained multibody (HDL). As a result, numerical algorithms for simula- dynamics. Nonlinear Dyn. 9, 113–130 (1996) tions based on Lagrangian dynamical systems can be 14. Udwadia, F.E., von Bremen, H.: Computation of Lyapunov automated more intelligently as it is apparent that one characteristic exponents for continuous dynamical systems. only needs to define the requisite Lagrangian L and Zeitschrift fur Angewandte Mathematik und Physik 53, 123–146 (2002) motion constraints φ and ψ for a given system.

References

1. Griewank, A., Walther, A.: Evaluating Derivatives, 2nd edn. Society for Industrial and Applied , Philadel- phia, PA (2008) 2. Rall, L.B.: Automatic Differentiation: Techniques and Applications, vol. 120. Springer, Heidelberg (1981)

123