title: Mass matrix
text: # Mass matrix
  
  In analytical mechanics, the mass matrix is a symmetric matrix M that expresses the connection between the time derivative $\mathbf {\dot {q}}$ of the generalized coordinate vector q of a system and the kinetic energy T of that system, by the equation
  
      $T={\frac {1}{2}}\mathbf {\dot {q}} ^{\textsf {T}}\mathbf {M} \mathbf {\dot {q}}$
  
  where $\mathbf {\dot {q}} ^{\textsf {T}}$ denotes the transpose of the vector $\mathbf {\dot {q}}$. This equation is analogous to the formula for the kinetic energy of a particle with mass m and velocity v, namely
  
      $T={\frac {1}{2}}m|\mathbf {v} |^{2}={\frac {1}{2}}\mathbf {v} \cdot m\mathbf {v}$
  
  and can be derived from it, by expressing the position of each particle of the system in terms of q.
  
  In general, the mass matrix M depends on the state q, and therefore varies with time.
  
  Lagrangian mechanics yields an ordinary differential equation (actually, a system of coupled differential equations) that describes the evolution of a system in terms of an arbitrary vector of generalized coordinates that completely defines the position of every particle in the system. The kinetic energy formula above is one term of that equation, that represents the total kinetic energy of all the particles.
  
  ## Examples
  
  ### Two-body unidimensional system
  
  For example, consider a system consisting of two point-like masses confined to a straight track. The state of that systems can be described by a vector q of two generalized coordinates, namely the positions of the two particles along the track.
  
      $\mathbf {q} ={\begin{bmatrix}x_{1}&x_{2}\end{bmatrix}}^{\textsf {T}}$
  
  Supposing the particles have masses $m_1,$ $m_2,$ the kinetic energy of the system is
  
      $T=\sum _{i=1}^{2}{\frac {1}{2}}m_{i}{\dot {x_{i}}}^{2}$
  
  This formula can also be written as
  
      $T={\frac {1}{2}}{\dot {\mathbf {q} }}^{\textsf {T}}\mathbf {M} {\dot {\mathbf {q} }}$
  
  where
  
      $\mathbf {M} ={\begin{bmatrix}m_{1}&0\\0&m_{2}\end{bmatrix}}$
  
  ### N-body system
  
  More generally, consider a system of N particles labelled by an index i = 1, 2, …, N, where the position of particle number i is defined by $n_i$ free Cartesian coordinates (where $n_i$ = 1, 2, 3). Let q be the column vector comprising all those coordinates. The mass matrix M is the diagonal block matrix where in each block the diagonal elements are the mass of the corresponding particle:
  
      $\mathbf {M} =\operatorname {diag} \left[m_{1}\mathbf {I} _{n_{1}},\,m_{2}\mathbf {I} _{n_{2}},\,\ldots ,\,m_{N}\mathbf {I} _{n_{N}}\right]$
  
  where $I_{ni}$ is the $n_i$ × $n_i$ identity matrix, or more fully:
  
      $\mathbf {M} ={\begin{bmatrix}m_{1}&\cdots &0&0&\cdots &0&\cdots &0&\cdots &0\\\vdots &\ddots &\vdots &\vdots &\ddots &\vdots &\ddots &\vdots &\ddots &\vdots \\0&\cdots &m_{1}&0&\cdots &0&\cdots &0&\cdots &0\\0&\cdots &0&m_{2}&\cdots &0&\cdots &0&\cdots &0\\\vdots &\ddots &\vdots &\vdots &\ddots &\vdots &\ddots &\vdots &\ddots &\vdots \\0&\cdots &0&0&\cdots &m_{2}&\cdots &0&\cdots &0\\\vdots &\ddots &\vdots &\vdots &\ddots &\vdots &\ddots &\vdots &\ddots &\vdots \\0&\cdots &0&0&\cdots &0&\cdots &m_{N}&\cdots &0\\\vdots &\ddots &\vdots &\vdots &\ddots &\vdots &\ddots &\vdots &\ddots &\vdots \\0&\cdots &0&0&\cdots &0&\cdots &0&\cdots &m_{N}\\\end{bmatrix}}$
  
  ### Rotating dumbbell
  
  For a less trivial example, consider two point-like objects with masses $m_1,$ $m_2,$ attached to the ends of a rigid massless bar with length 2R, the assembly being free to rotate and slide over a fixed plane. The state of the system can be described by the generalized coordinate vector
  
      $\mathbf {q} ={\begin{bmatrix}x&y&\alpha \end{bmatrix}}$
  
  where x, y are the Cartesian coordinates of the bar's midpoint and α is the angle of the bar from some arbitrary reference direction. The positions and velocities of the two particles are
  
      ${\begin{aligned}x_{1}&=(x,y)+R(\cos \alpha ,\sin \alpha )&v_{1}&=\left({\dot {x}},{\dot {y}}\right)+R{\dot {\alpha }}(-\sin \alpha ,\cos \alpha )\\x_{2}&=(x,y)-R(\cos \alpha ,\sin \alpha )&v_{2}&=\left({\dot {x}},{\dot {y}}\right)-R{\dot {\alpha }}(-\sin \alpha ,\cos \alpha )\end{aligned}}$
  
  and their total kinetic energy is
  
      $2T=m{\dot {x}}^{2}+m{\dot {y}}^{2}+mR^{2}{\dot {\alpha }}^{2}-2Rd\sin(\alpha ){\dot {x}}{\dot {\alpha }}+2Rd\cos(\alpha ){\dot {y}}{\dot {\alpha }}$
  
  where $m=m_{1}+m_{2}$ and $d=m_{1}-m_{2}$. This formula can be written in matrix form as
  
      $T={\frac {1}{2}}{\dot {\mathbf {q} }}^{\textsf {T}}\mathbf {M} {\dot {\mathbf {q} }}$
  
  where
  
      $\mathbf {M} ={\begin{bmatrix}m&0&-Rd\sin \alpha \\0&m&Rd\cos \alpha \\-Rd\sin \alpha &Rd\cos \alpha &R^{2}m\end{bmatrix}}$
  
  Note that the matrix depends on the current angle α of the bar.
  
  ## Continuum mechanics
  
  For discrete approximations of continuum mechanics as in the finite element method, there may be more than one way to construct the mass matrix, depending on desired computational accuracy and performance. For example, a lumped-mass method, in which the deformation of each element is ignored, creates a diagonal mass matrix and negates the need to integrate mass across the deformed element.
  
  