# Rearranging the system matrices from  (Lin, Parker, 1999)

[1] Lin, J., & Parker, R. G. (1999). Analytical characterization of the unique properties of planetary gear free vibration. Journal of Vibration and Acoustics, Transactions of the ASME, 121(3), 316–321. http://doi.org/10.1115/1.2893982 \
[2] Cooley, C. G., & Parker, R. G. (2012). Vibration Properties of High-Speed Planetary Gears With Gyroscopic Effects. Journal of Vibration and Acoustics, 134(6). http://doi.org/10.1115/1.4006646

```python
from sympy import *
init_printing()

def symb(x,y):
    return symbols('{0}_{1}'.format(x,y), type = float)
```

## Displacement vector

The rotational coordinates are represented indirectly in the following way:
$$u_j = r_j \theta_j,$$
where $r_j$ is the base radius of sun, ring, and planets gears or the center distance for the carrier

```python
N = 3 # number of planets
N_DOF = 3*(N + 3) # number of degrees of freedom
crs = ['c', 'r', 's'] # carrier, ring, sun
pla = ['p{}'.format(idx + 1) for idx in range(N)] # planet
crs = crs + pla # put them together

coeff_list = symbols(crs)
c = coeff_list[0]
r = coeff_list[1]
s = coeff_list[2]

q = Matrix([symbols('x_{0} y_{0} u_{0}'.format(v)) for v in coeff_list])
coeff_list[3:] = symbols(['p']*N)
p = coeff_list[3]
q = q.reshape(N_DOF, 1)
transpose(q) # Eq. (2)
```

$\displaystyle \left[\begin{array}{cccccccccccccccccc}x_{c} & y_{c} & u_{c} & x_{r} & y_{r} & u_{r} & x_{s} & y_{s} & u_{s} & x_{p1} & y_{p1} & u_{p1} & x_{p2} & y_{p2} & u_{p2} & x_{p3} & y_{p3} & u_{p3}\end{array}\right]$

## Inertia matrix

First one needs to write the system matrices, defined in the Appendix of [1]. The inertia matrix can be seen in the figure below:

where:
* $N$ is the number of planets
* $m_j$ is the mass of an element (sun, planet, ring, carrier)
* $I_j$ is the mass moment of inertia of an element
* $r_j$ is the base radius for sun, ring, and planet gears or the center distance for the carrier

```python
func = lambda x: diag(symb('m', x), symb('m', x), symb('I', x)/symb('r', x)**2)
M = diag(*[[func(v)] for v in coeff_list])
M
```

$\displaystyle \left[\begin{array}{cccccccccccccccccc}m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & \frac{I_{c}}{r_{c}^{2}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & m_{r} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & m_{r} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & \frac{I_{r}}{r_{r}^{2}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{I_{s}}{r_{s}^{2}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{I_{p}}{r_{p}^{2}} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{I_{p}}{r_{p}^{2}} & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{I_{p}}{r_{p}^{2}}\end{array}\right]$

## Gyroscopic matrix:

```python
func = lambda x: Matrix(3, 3, [0, -2*symb('m', x), 0, 2*symb('m', x), 0, 0, 0, 0, 0])
G = diag(*[[func(v)] for v in coeff_list])
G
```

$\displaystyle \left[\begin{array}{cccccccccccccccccc}0 & - 2 m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & - 2 m_{r} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 2 m_{r} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & - 2 m_{s} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 2 m_{s} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - 2 m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - 2 m_{p} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 m_{p} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - 2 m_{p} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 m_{p} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right]$

## Stiffness matrix

### Centripetal component

```python
func = lambda x: diag(symb('m', x), symb('m', x), 0)
K_omega = diag(*[[func(v)] for v in coeff_list])
K_omega
```

$\displaystyle \left[\begin{array}{cccccccccccccccccc}m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & m_{r} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & m_{r} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right]$

### Bearing component:

```python
k_sub = lambda x, y: symbols('k_{0}{1}'.format(x, y), type = float)
func = lambda z: diag(k_sub(z, 'x'), k_sub(z, 'y'), k_sub(z, 'u')) if(z != p) else zeros(3)
K_b = diag(*[[func(v)] for v in coeff_list])
K_b
```

$\displaystyle \left[\begin{array}{cccccccccccccccccc}k_{cx} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & k_{cy} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & k_{cu} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & k_{rx} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & k_{ry} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & k_{ru} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & k_{sx} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & k_{sy} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & k_{su} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right]$

where $k_{ix}$ and $k_{iy}$ are the bearing stiffness components in the $x$ and $y$ directions. The torsional components of the bearing stiffness are null, i.e. $k_{iu} = 0$, for $i = c, r, s$.

```python
K_b = K_b.subs([(k_sub(v, 'u'), 0) for v in [c, r, s]])
K_b
```

$\displaystyle \left[\begin{array}{cccccccccccccccccc}k_{cx} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & k_{cy} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & k_{rx} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & k_{ry} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & k_{sx} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & k_{sy} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right]$

### Mesh component:

First one needs to write the system matrices, defined in the Appendix of [1].

```python
psi, alpha_s, alpha_r = symbols('psi alpha_s alpha_r', type = float)
psi_s = lambda x: symb(psi, x) - alpha_s
psi_r = lambda x: symb(psi, x) + alpha_r
```

where $\alpha_{s/r}$ are the pressure angles of sun and ring gears.

```python
K_c1 = lambda x: k_sub(p, x)*Matrix([[ 1                , 0                , -sin(symb(psi, x))],
                                     [ 0                , 1                ,  cos(symb(psi, x))],
                                     [-sin(symb(psi, x)), cos(symb(psi, x)),  1]])
k_tmp = K_c1('j')
if(not k_tmp.is_symmetric()):
    print('error.')
k_tmp
```

$\displaystyle \left[\begin{matrix}k_{pj} & 0 & - k_{pj} \sin{\left(\psi_{j} \right)}\\0 & k_{pj} & k_{pj} \cos{\left(\psi_{j} \right)}\\- k_{pj} \sin{\left(\psi_{j} \right)} & k_{pj} \cos{\left(\psi_{j} \right)} & k_{pj}\end{matrix}\right]$

where:
* $k_{pj}$ is the $j$-th planet bearing stiffness
* $\psi_j$ is the circumferential location of the $j$-th planet

notice that there are not $x$, $y$, or $u$ components for the planet bearing, different from the bearings for carrier, ring, and sun.

```python
K_c2 = lambda x: k_sub(p, x)*Matrix([[-cos(symb(psi, x)),  sin(symb(psi, x)), 0],
                                     [-sin(symb(psi, x)), -cos(symb(psi, x)), 0],
                                     [ 0                , -1                , 0]])
k_tmp = K_c2('j')
k_tmp
```

$\displaystyle \left[\begin{matrix}- k_{pj} \cos{\left(\psi_{j} \right)} & k_{pj} \sin{\left(\psi_{j} \right)} & 0\\- k_{pj} \sin{\left(\psi_{j} \right)} & - k_{pj} \cos{\left(\psi_{j} \right)} & 0\\0 & - k_{pj} & 0\end{matrix}\right]$

```python
K_c3 = lambda x: diag(k_sub(p, x), k_sub(p, x), 0)
K_c3('j')
```

$\displaystyle \left[\begin{matrix}k_{pj} & 0 & 0\\0 & k_{pj} & 0\\0 & 0 & 0\end{matrix}\right]$

One can rewrite the matrices $\mathbf{K}_{ci}^n$ in order to account for anysotropic bearings:
$$
\mathbf{K}_{ci}^n({\rm new}) = \frac{1}{k_{pj}}\mathbf{K}_{ci}^n({\rm old}) {\rm diag}(k_{px}, k_{py}, k_{pu})
$$

```python
def K_c(i, x):
    if(i == 1):
        k_old = K_c1(x)
    elif(i == 2):
        k_old = K_c2(x)
    elif(i == 3):
        k_old = K_c3(x)
    else:
        print('ERROR inf K_c(), i = {} is out of range.'.format(i))

    return (1/k_sub(p, x))*diag(k_sub(p, 'x'), k_sub(p, 'y'), k_sub(p, 'u'))*k_old

K_c(2,'j')
```

$\displaystyle \left[\begin{matrix}- k_{px} \cos{\left(\psi_{j} \right)} & k_{px} \sin{\left(\psi_{j} \right)} & 0\\- k_{py} \sin{\left(\psi_{j} \right)} & - k_{py} \cos{\left(\psi_{j} \right)} & 0\\0 & - k_{pu} & 0\end{matrix}\right]$

```python
K_r1 = lambda x: k_sub(r, x)*Matrix([[               sin(psi_r(x))**2, -cos(psi_r(x))*sin(psi_r(x)), -sin(psi_r(x))],
                                     [-cos(psi_r(x))*sin(psi_r(x))   ,  cos(psi_r(x))**2           ,  cos(psi_r(x))],
                                     [-              sin(psi_r(x))   ,  cos(psi_r(x))              ,  1]])
k_tmp = K_r1('j')
if(not k_tmp.is_symmetric()):
    print('error.')
k_tmp
```

$\displaystyle \left[\begin{matrix}k_{rj} \sin^{2}{\left(\alpha_{r} + \psi_{j} \right)} & - k_{rj} \sin{\left(\alpha_{r} + \psi_{j} \right)} \cos{\left(\alpha_{r} + \psi_{j} \right)} & - k_{rj} \sin{\left(\alpha_{r} + \psi_{j} \right)}\\- k_{rj} \sin{\left(\alpha_{r} + \psi_{j} \right)} \cos{\left(\alpha_{r} + \psi_{j} \right)} & k_{rj} \cos^{2}{\left(\alpha_{r} + \psi_{j} \right)} & k_{rj} \cos{\left(\alpha_{r} + \psi_{j} \right)}\\- k_{rj} \sin{\left(\alpha_{r} + \psi_{j} \right)} & k_{rj} \cos{\left(\alpha_{r} + \psi_{j} \right)} & k_{rj}\end{matrix}\right]$

where $k_{rj}$ is the mesh stiffness between the ring and the $j$-th planet

```python
K_r2 = lambda x: k_sub(r, x)*Matrix([[-sin(psi_r(x))*sin(alpha_r),  sin(psi_r(x))*cos(alpha_r),  sin(psi_r(x))],
                                     [ cos(psi_r(x))*sin(alpha_r), -cos(psi_r(x))*cos(alpha_r), -cos(psi_r(x))],
                                     [               sin(alpha_r), -              cos(alpha_r), -1]])
k_tmp = K_r2('j')
k_tmp
```

$\displaystyle \left[\begin{matrix}- k_{rj} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{j} \right)} & k_{rj} \sin{\left(\alpha_{r} + \psi_{j} \right)} \cos{\left(\alpha_{r} \right)} & k_{rj} \sin{\left(\alpha_{r} + \psi_{j} \right)}\\k_{rj} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{j} \right)} & - k_{rj} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{j} \right)} & - k_{rj} \cos{\left(\alpha_{r} + \psi_{j} \right)}\\k_{rj} \sin{\left(\alpha_{r} \right)} & - k_{rj} \cos{\left(\alpha_{r} \right)} & - k_{rj}\end{matrix}\right]$

```python
K_r3 = lambda x: k_sub(r, x)*Matrix([[ sin(alpha_r)**2          , -sin(alpha_r)*cos(alpha_r), -sin(alpha_r)],
                                     [-sin(alpha_r)*cos(alpha_r),  cos(alpha_r)**2          ,  cos(alpha_r)],
                                     [-sin(alpha_r)             ,  cos(alpha_r)             ,  1]])
k_tmp = K_r3('j')
if(not k_tmp.is_symmetric()):
    print('error.')
k_tmp
```

$\displaystyle \left[\begin{matrix}k_{rj} \sin^{2}{\left(\alpha_{r} \right)} & - k_{rj} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} & - k_{rj} \sin{\left(\alpha_{r} \right)}\\- k_{rj} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} & k_{rj} \cos^{2}{\left(\alpha_{r} \right)} & k_{rj} \cos{\left(\alpha_{r} \right)}\\- k_{rj} \sin{\left(\alpha_{r} \right)} & k_{rj} \cos{\left(\alpha_{r} \right)} & k_{rj}\end{matrix}\right]$

```python
K_s1 = lambda x: k_sub(s, x)*Matrix([[               sin(psi_s(x))**2, -cos(psi_s(x))*sin(psi_s(x)), -sin(psi_s(x))],
                                     [-cos(psi_s(x))*sin(psi_s(x))   ,  cos(psi_s(x))**2           ,  cos(psi_s(x))],
                                     [-              sin(psi_s(x))   ,  cos(psi_s(x))              ,  1]])
k_tmp = K_s1('j')
if(not k_tmp.is_symmetric()):
    print('error.')
k_tmp
```

$\displaystyle \left[\begin{matrix}k_{sj} \sin^{2}{\left(\alpha_{s} - \psi_{j} \right)} & k_{sj} \sin{\left(\alpha_{s} - \psi_{j} \right)} \cos{\left(\alpha_{s} - \psi_{j} \right)} & k_{sj} \sin{\left(\alpha_{s} - \psi_{j} \right)}\\k_{sj} \sin{\left(\alpha_{s} - \psi_{j} \right)} \cos{\left(\alpha_{s} - \psi_{j} \right)} & k_{sj} \cos^{2}{\left(\alpha_{s} - \psi_{j} \right)} & k_{sj} \cos{\left(\alpha_{s} - \psi_{j} \right)}\\k_{sj} \sin{\left(\alpha_{s} - \psi_{j} \right)} & k_{sj} \cos{\left(\alpha_{s} - \psi_{j} \right)} & k_{sj}\end{matrix}\right]$

where $k_{sj}$ is the mesh stiffness between the sun and the $j$-th planet

```python
K_s2 = lambda x: k_sub(s, x)*Matrix([[ sin(psi_s(x))*sin(alpha_s),  sin(psi_s(x))*cos(alpha_s), -sin(psi_s(x))],
                                     [-cos(psi_s(x))*sin(alpha_s), -cos(psi_s(x))*cos(alpha_s),  cos(psi_s(x))],
                                     [-              sin(alpha_s), -              cos(alpha_s),  1]])
k_tmp = K_s2('j')
k_tmp
```

$\displaystyle \left[\begin{matrix}- k_{sj} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{j} \right)} & - k_{sj} \sin{\left(\alpha_{s} - \psi_{j} \right)} \cos{\left(\alpha_{s} \right)} & k_{sj} \sin{\left(\alpha_{s} - \psi_{j} \right)}\\- k_{sj} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{j} \right)} & - k_{sj} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{j} \right)} & k_{sj} \cos{\left(\alpha_{s} - \psi_{j} \right)}\\- k_{sj} \sin{\left(\alpha_{s} \right)} & - k_{sj} \cos{\left(\alpha_{s} \right)} & k_{sj}\end{matrix}\right]$

```python
K_s3 = lambda x: k_sub(s, x)*Matrix([[ sin(alpha_s)**2          ,  sin(alpha_s)*cos(alpha_s), -sin(alpha_s)],
                                     [ sin(alpha_s)*cos(alpha_s),  cos(alpha_s)**2          , -cos(alpha_s)],
                                     [-sin(alpha_s)             , -cos(alpha_s)             ,  1]])
k_tmp = K_s3('j')
if(not k_tmp.is_symmetric()):
    print('error.')
k_tmp
```

$\displaystyle \left[\begin{matrix}k_{sj} \sin^{2}{\left(\alpha_{s} \right)} & k_{sj} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & - k_{sj} \sin{\left(\alpha_{s} \right)}\\k_{sj} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & k_{sj} \cos^{2}{\left(\alpha_{s} \right)} & - k_{sj} \cos{\left(\alpha_{s} \right)}\\- k_{sj} \sin{\left(\alpha_{s} \right)} & - k_{sj} \cos{\left(\alpha_{s} \right)} & k_{sj}\end{matrix}\right]$

```python
K_pp = lambda x: K_c3(x) + K_r3(x) + K_s3(x)
K_pp('j')
```

$\displaystyle \left[\begin{matrix}k_{pj} + k_{rj} \sin^{2}{\left(\alpha_{r} \right)} + k_{sj} \sin^{2}{\left(\alpha_{s} \right)} & - k_{rj} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{sj} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & - k_{rj} \sin{\left(\alpha_{r} \right)} - k_{sj} \sin{\left(\alpha_{s} \right)}\\- k_{rj} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{sj} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & k_{pj} + k_{rj} \cos^{2}{\left(\alpha_{r} \right)} + k_{sj} \cos^{2}{\left(\alpha_{s} \right)} & k_{rj} \cos{\left(\alpha_{r} \right)} - k_{sj} \cos{\left(\alpha_{s} \right)}\\- k_{rj} \sin{\left(\alpha_{r} \right)} - k_{sj} \sin{\left(\alpha_{s} \right)} & k_{rj} \cos{\left(\alpha_{r} \right)} - k_{sj} \cos{\left(\alpha_{s} \right)} & k_{rj} + k_{sj}\end{matrix}\right]$

The mesh stiffness matrix is defined in the figure below, where it is sub-divided in blocks with colors, red, grey, and blue, called diagonal 1, diagonal 2, and off-diagonal, respectively. As mentioned previously, the matrices $\mathbf{K}_{c2}^N$ are proportional to the bearing stiffness, having no relation with the mesh stiffness.

##### Diagonal 1

```python
sum_Kc1 = sum([K_c1(n + 1) for n in range(N)], zeros(3))
sum_Kr1 = sum([K_r1(n + 1) for n in range(N)], zeros(3))
sum_Ks1 = sum([K_s1(n + 1) for n in range(N)], zeros(3))

K_d1 = diag(sum_Kc1, sum_Kr1, sum_Ks1)
K_d1
```

$\displaystyle \left[\begin{matrix}k_{p1} + k_{p2} + k_{p3} & 0 & - k_{p1} \sin{\left(\psi_{1} \right)} - k_{p2} \sin{\left(\psi_{2} \right)} - k_{p3} \sin{\left(\psi_{3} \right)} & 0 & 0 & 0 & 0 & 0 & 0\\0 & k_{p1} + k_{p2} + k_{p3} & k_{p1} \cos{\left(\psi_{1} \right)} + k_{p2} \cos{\left(\psi_{2} \right)} + k_{p3} \cos{\left(\psi_{3} \right)} & 0 & 0 & 0 & 0 & 0 & 0\\- k_{p1} \sin{\left(\psi_{1} \right)} - k_{p2} \sin{\left(\psi_{2} \right)} - k_{p3} \sin{\left(\psi_{3} \right)} & k_{p1} \cos{\left(\psi_{1} \right)} + k_{p2} \cos{\left(\psi_{2} \right)} + k_{p3} \cos{\left(\psi_{3} \right)} & k_{p1} + k_{p2} + k_{p3} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & k_{r1} \sin^{2}{\left(\alpha_{r} + \psi_{1} \right)} + k_{r2} \sin^{2}{\left(\alpha_{r} + \psi_{2} \right)} + k_{r3} \sin^{2}{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} - k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} - k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} - k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} - k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} & 0 & 0 & 0\\0 & 0 & 0 & - k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} - k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} - k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & k_{r1} \cos^{2}{\left(\alpha_{r} + \psi_{1} \right)} + k_{r2} \cos^{2}{\left(\alpha_{r} + \psi_{2} \right)} + k_{r3} \cos^{2}{\left(\alpha_{r} + \psi_{3} \right)} & k_{r1} \cos{\left(\alpha_{r} + \psi_{1} \right)} + k_{r2} \cos{\left(\alpha_{r} + \psi_{2} \right)} + k_{r3} \cos{\left(\alpha_{r} + \psi_{3} \right)} & 0 & 0 & 0\\0 & 0 & 0 & - k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} - k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} - k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} & k_{r1} \cos{\left(\alpha_{r} + \psi_{1} \right)} + k_{r2} \cos{\left(\alpha_{r} + \psi_{2} \right)} + k_{r3} \cos{\left(\alpha_{r} + \psi_{3} \right)} & k_{r1} + k_{r2} + k_{r3} & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & k_{s1} \sin^{2}{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin^{2}{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin^{2}{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)}\\0 & 0 & 0 & 0 & 0 & 0 & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \cos^{2}{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \cos^{2}{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \cos^{2}{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \cos{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \cos{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \cos{\left(\alpha_{s} - \psi_{3} \right)}\\0 & 0 & 0 & 0 & 0 & 0 & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \cos{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \cos{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \cos{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} + k_{s2} + k_{s3}\end{matrix}\right]$

##### Diagonal 2

```python
K_d2 = diag(*[K_pp(n + 1) for n in range(N)])
K_d2
```

$\displaystyle \left[\begin{matrix}k_{p1} + k_{r1} \sin^{2}{\left(\alpha_{r} \right)} + k_{s1} \sin^{2}{\left(\alpha_{s} \right)} & - k_{r1} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s1} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & - k_{r1} \sin{\left(\alpha_{r} \right)} - k_{s1} \sin{\left(\alpha_{s} \right)} & 0 & 0 & 0 & 0 & 0 & 0\\- k_{r1} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s1} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & k_{p1} + k_{r1} \cos^{2}{\left(\alpha_{r} \right)} + k_{s1} \cos^{2}{\left(\alpha_{s} \right)} & k_{r1} \cos{\left(\alpha_{r} \right)} - k_{s1} \cos{\left(\alpha_{s} \right)} & 0 & 0 & 0 & 0 & 0 & 0\\- k_{r1} \sin{\left(\alpha_{r} \right)} - k_{s1} \sin{\left(\alpha_{s} \right)} & k_{r1} \cos{\left(\alpha_{r} \right)} - k_{s1} \cos{\left(\alpha_{s} \right)} & k_{r1} + k_{s1} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & k_{p2} + k_{r2} \sin^{2}{\left(\alpha_{r} \right)} + k_{s2} \sin^{2}{\left(\alpha_{s} \right)} & - k_{r2} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s2} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & - k_{r2} \sin{\left(\alpha_{r} \right)} - k_{s2} \sin{\left(\alpha_{s} \right)} & 0 & 0 & 0\\0 & 0 & 0 & - k_{r2} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s2} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & k_{p2} + k_{r2} \cos^{2}{\left(\alpha_{r} \right)} + k_{s2} \cos^{2}{\left(\alpha_{s} \right)} & k_{r2} \cos{\left(\alpha_{r} \right)} - k_{s2} \cos{\left(\alpha_{s} \right)} & 0 & 0 & 0\\0 & 0 & 0 & - k_{r2} \sin{\left(\alpha_{r} \right)} - k_{s2} \sin{\left(\alpha_{s} \right)} & k_{r2} \cos{\left(\alpha_{r} \right)} - k_{s2} \cos{\left(\alpha_{s} \right)} & k_{r2} + k_{s2} & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & k_{p3} + k_{r3} \sin^{2}{\left(\alpha_{r} \right)} + k_{s3} \sin^{2}{\left(\alpha_{s} \right)} & - k_{r3} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s3} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & - k_{r3} \sin{\left(\alpha_{r} \right)} - k_{s3} \sin{\left(\alpha_{s} \right)}\\0 & 0 & 0 & 0 & 0 & 0 & - k_{r3} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s3} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & k_{p3} + k_{r3} \cos^{2}{\left(\alpha_{r} \right)} + k_{s3} \cos^{2}{\left(\alpha_{s} \right)} & k_{r3} \cos{\left(\alpha_{r} \right)} - k_{s3} \cos{\left(\alpha_{s} \right)}\\0 & 0 & 0 & 0 & 0 & 0 & - k_{r3} \sin{\left(\alpha_{r} \right)} - k_{s3} \sin{\left(\alpha_{s} \right)} & k_{r3} \cos{\left(\alpha_{r} \right)} - k_{s3} \cos{\left(\alpha_{s} \right)} & k_{r3} + k_{s3}\end{matrix}\right]$

##### Off-diagonal

```python
K_od = BlockMatrix([[K_c2(idx + 1) for idx in range(N)],
                    [K_r2(idx + 1) for idx in range(N)],
                    [K_s2(idx + 1) for idx in range(N)]])
K_od = Matrix(K_od)
K_od
```

$\displaystyle \left[\begin{matrix}- k_{p1} \cos{\left(\psi_{1} \right)} & k_{p1} \sin{\left(\psi_{1} \right)} & 0 & - k_{p2} \cos{\left(\psi_{2} \right)} & k_{p2} \sin{\left(\psi_{2} \right)} & 0 & - k_{p3} \cos{\left(\psi_{3} \right)} & k_{p3} \sin{\left(\psi_{3} \right)} & 0\\- k_{p1} \sin{\left(\psi_{1} \right)} & - k_{p1} \cos{\left(\psi_{1} \right)} & 0 & - k_{p2} \sin{\left(\psi_{2} \right)} & - k_{p2} \cos{\left(\psi_{2} \right)} & 0 & - k_{p3} \sin{\left(\psi_{3} \right)} & - k_{p3} \cos{\left(\psi_{3} \right)} & 0\\0 & - k_{p1} & 0 & 0 & - k_{p2} & 0 & 0 & - k_{p3} & 0\\- k_{r1} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{1} \right)} & k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} \cos{\left(\alpha_{r} \right)} & k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} & - k_{r2} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{2} \right)} & k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} \cos{\left(\alpha_{r} \right)} & k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} & - k_{r3} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{3} \right)} & k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} \cos{\left(\alpha_{r} \right)} & k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)}\\k_{r1} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} & - k_{r1} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} & - k_{r1} \cos{\left(\alpha_{r} + \psi_{1} \right)} & k_{r2} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} & - k_{r2} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} & - k_{r2} \cos{\left(\alpha_{r} + \psi_{2} \right)} & k_{r3} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r3} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r3} \cos{\left(\alpha_{r} + \psi_{3} \right)}\\k_{r1} \sin{\left(\alpha_{r} \right)} & - k_{r1} \cos{\left(\alpha_{r} \right)} & - k_{r1} & k_{r2} \sin{\left(\alpha_{r} \right)} & - k_{r2} \cos{\left(\alpha_{r} \right)} & - k_{r2} & k_{r3} \sin{\left(\alpha_{r} \right)} & - k_{r3} \cos{\left(\alpha_{r} \right)} & - k_{r3}\\- k_{s1} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} \cos{\left(\alpha_{s} \right)} & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s2} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} \cos{\left(\alpha_{s} \right)} & k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s3} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{3} \right)} & - k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} \cos{\left(\alpha_{s} \right)} & k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)}\\- k_{s1} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s1} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} & k_{s1} \cos{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s2} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s2} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} & k_{s2} \cos{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s3} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & - k_{s3} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & k_{s3} \cos{\left(\alpha_{s} - \psi_{3} \right)}\\- k_{s1} \sin{\left(\alpha_{s} \right)} & - k_{s1} \cos{\left(\alpha_{s} \right)} & k_{s1} & - k_{s2} \sin{\left(\alpha_{s} \right)} & - k_{s2} \cos{\left(\alpha_{s} \right)} & k_{s2} & - k_{s3} \sin{\left(\alpha_{s} \right)} & - k_{s3} \cos{\left(\alpha_{s} \right)} & k_{s3}\end{matrix}\right]$

#### Assembly

```python
K_m = BlockMatrix([[          K_d1 , K_od],
                   [transpose(K_od), K_d2]])
K_m = Matrix(K_m)
k_tmp = K_m
if(not k_tmp.is_symmetric()):
    print('error.')
k_tmp
```

$\displaystyle \left[\begin{array}{cccccccccccccccccc}k_{p1} + k_{p2} + k_{p3} & 0 & - k_{p1} \sin{\left(\psi_{1} \right)} - k_{p2} \sin{\left(\psi_{2} \right)} - k_{p3} \sin{\left(\psi_{3} \right)} & 0 & 0 & 0 & 0 & 0 & 0 & - k_{p1} \cos{\left(\psi_{1} \right)} & k_{p1} \sin{\left(\psi_{1} \right)} & 0 & - k_{p2} \cos{\left(\psi_{2} \right)} & k_{p2} \sin{\left(\psi_{2} \right)} & 0 & - k_{p3} \cos{\left(\psi_{3} \right)} & k_{p3} \sin{\left(\psi_{3} \right)} & 0\\0 & k_{p1} + k_{p2} + k_{p3} & k_{p1} \cos{\left(\psi_{1} \right)} + k_{p2} \cos{\left(\psi_{2} \right)} + k_{p3} \cos{\left(\psi_{3} \right)} & 0 & 0 & 0 & 0 & 0 & 0 & - k_{p1} \sin{\left(\psi_{1} \right)} & - k_{p1} \cos{\left(\psi_{1} \right)} & 0 & - k_{p2} \sin{\left(\psi_{2} \right)} & - k_{p2} \cos{\left(\psi_{2} \right)} & 0 & - k_{p3} \sin{\left(\psi_{3} \right)} & - k_{p3} \cos{\left(\psi_{3} \right)} & 0\\- k_{p1} \sin{\left(\psi_{1} \right)} - k_{p2} \sin{\left(\psi_{2} \right)} - k_{p3} \sin{\left(\psi_{3} \right)} & k_{p1} \cos{\left(\psi_{1} \right)} + k_{p2} \cos{\left(\psi_{2} \right)} + k_{p3} \cos{\left(\psi_{3} \right)} & k_{p1} + k_{p2} + k_{p3} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - k_{p1} & 0 & 0 & - k_{p2} & 0 & 0 & - k_{p3} & 0\\0 & 0 & 0 & k_{r1} \sin^{2}{\left(\alpha_{r} + \psi_{1} \right)} + k_{r2} \sin^{2}{\left(\alpha_{r} + \psi_{2} \right)} + k_{r3} \sin^{2}{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} - k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} - k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} - k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} - k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} & 0 & 0 & 0 & - k_{r1} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{1} \right)} & k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} \cos{\left(\alpha_{r} \right)} & k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} & - k_{r2} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{2} \right)} & k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} \cos{\left(\alpha_{r} \right)} & k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} & - k_{r3} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{3} \right)} & k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} \cos{\left(\alpha_{r} \right)} & k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)}\\0 & 0 & 0 & - k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} - k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} - k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & k_{r1} \cos^{2}{\left(\alpha_{r} + \psi_{1} \right)} + k_{r2} \cos^{2}{\left(\alpha_{r} + \psi_{2} \right)} + k_{r3} \cos^{2}{\left(\alpha_{r} + \psi_{3} \right)} & k_{r1} \cos{\left(\alpha_{r} + \psi_{1} \right)} + k_{r2} \cos{\left(\alpha_{r} + \psi_{2} \right)} + k_{r3} \cos{\left(\alpha_{r} + \psi_{3} \right)} & 0 & 0 & 0 & k_{r1} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} & - k_{r1} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} & - k_{r1} \cos{\left(\alpha_{r} + \psi_{1} \right)} & k_{r2} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} & - k_{r2} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} & - k_{r2} \cos{\left(\alpha_{r} + \psi_{2} \right)} & k_{r3} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r3} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r3} \cos{\left(\alpha_{r} + \psi_{3} \right)}\\0 & 0 & 0 & - k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} - k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} - k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} & k_{r1} \cos{\left(\alpha_{r} + \psi_{1} \right)} + k_{r2} \cos{\left(\alpha_{r} + \psi_{2} \right)} + k_{r3} \cos{\left(\alpha_{r} + \psi_{3} \right)} & k_{r1} + k_{r2} + k_{r3} & 0 & 0 & 0 & k_{r1} \sin{\left(\alpha_{r} \right)} & - k_{r1} \cos{\left(\alpha_{r} \right)} & - k_{r1} & k_{r2} \sin{\left(\alpha_{r} \right)} & - k_{r2} \cos{\left(\alpha_{r} \right)} & - k_{r2} & k_{r3} \sin{\left(\alpha_{r} \right)} & - k_{r3} \cos{\left(\alpha_{r} \right)} & - k_{r3}\\0 & 0 & 0 & 0 & 0 & 0 & k_{s1} \sin^{2}{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin^{2}{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin^{2}{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} & - k_{s1} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} \cos{\left(\alpha_{s} \right)} & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s2} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} \cos{\left(\alpha_{s} \right)} & k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s3} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{3} \right)} & - k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} \cos{\left(\alpha_{s} \right)} & k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)}\\0 & 0 & 0 & 0 & 0 & 0 & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \cos^{2}{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \cos^{2}{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \cos^{2}{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \cos{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \cos{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \cos{\left(\alpha_{s} - \psi_{3} \right)} & - k_{s1} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s1} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} & k_{s1} \cos{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s2} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s2} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} & k_{s2} \cos{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s3} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & - k_{s3} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & k_{s3} \cos{\left(\alpha_{s} - \psi_{3} \right)}\\0 & 0 & 0 & 0 & 0 & 0 & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} \cos{\left(\alpha_{s} - \psi_{1} \right)} + k_{s2} \cos{\left(\alpha_{s} - \psi_{2} \right)} + k_{s3} \cos{\left(\alpha_{s} - \psi_{3} \right)} & k_{s1} + k_{s2} + k_{s3} & - k_{s1} \sin{\left(\alpha_{s} \right)} & - k_{s1} \cos{\left(\alpha_{s} \right)} & k_{s1} & - k_{s2} \sin{\left(\alpha_{s} \right)} & - k_{s2} \cos{\left(\alpha_{s} \right)} & k_{s2} & - k_{s3} \sin{\left(\alpha_{s} \right)} & - k_{s3} \cos{\left(\alpha_{s} \right)} & k_{s3}\\- k_{p1} \cos{\left(\psi_{1} \right)} & - k_{p1} \sin{\left(\psi_{1} \right)} & 0 & - k_{r1} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{1} \right)} & k_{r1} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} & k_{r1} \sin{\left(\alpha_{r} \right)} & - k_{s1} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s1} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s1} \sin{\left(\alpha_{s} \right)} & k_{p1} + k_{r1} \sin^{2}{\left(\alpha_{r} \right)} + k_{s1} \sin^{2}{\left(\alpha_{s} \right)} & - k_{r1} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s1} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & - k_{r1} \sin{\left(\alpha_{r} \right)} - k_{s1} \sin{\left(\alpha_{s} \right)} & 0 & 0 & 0 & 0 & 0 & 0\\k_{p1} \sin{\left(\psi_{1} \right)} & - k_{p1} \cos{\left(\psi_{1} \right)} & - k_{p1} & k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} \cos{\left(\alpha_{r} \right)} & - k_{r1} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{1} \right)} & - k_{r1} \cos{\left(\alpha_{r} \right)} & - k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} \cos{\left(\alpha_{s} \right)} & - k_{s1} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{1} \right)} & - k_{s1} \cos{\left(\alpha_{s} \right)} & - k_{r1} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s1} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & k_{p1} + k_{r1} \cos^{2}{\left(\alpha_{r} \right)} + k_{s1} \cos^{2}{\left(\alpha_{s} \right)} & k_{r1} \cos{\left(\alpha_{r} \right)} - k_{s1} \cos{\left(\alpha_{s} \right)} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & k_{r1} \sin{\left(\alpha_{r} + \psi_{1} \right)} & - k_{r1} \cos{\left(\alpha_{r} + \psi_{1} \right)} & - k_{r1} & k_{s1} \sin{\left(\alpha_{s} - \psi_{1} \right)} & k_{s1} \cos{\left(\alpha_{s} - \psi_{1} \right)} & k_{s1} & - k_{r1} \sin{\left(\alpha_{r} \right)} - k_{s1} \sin{\left(\alpha_{s} \right)} & k_{r1} \cos{\left(\alpha_{r} \right)} - k_{s1} \cos{\left(\alpha_{s} \right)} & k_{r1} + k_{s1} & 0 & 0 & 0 & 0 & 0 & 0\\- k_{p2} \cos{\left(\psi_{2} \right)} & - k_{p2} \sin{\left(\psi_{2} \right)} & 0 & - k_{r2} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{2} \right)} & k_{r2} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} & k_{r2} \sin{\left(\alpha_{r} \right)} & - k_{s2} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s2} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s2} \sin{\left(\alpha_{s} \right)} & 0 & 0 & 0 & k_{p2} + k_{r2} \sin^{2}{\left(\alpha_{r} \right)} + k_{s2} \sin^{2}{\left(\alpha_{s} \right)} & - k_{r2} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s2} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & - k_{r2} \sin{\left(\alpha_{r} \right)} - k_{s2} \sin{\left(\alpha_{s} \right)} & 0 & 0 & 0\\k_{p2} \sin{\left(\psi_{2} \right)} & - k_{p2} \cos{\left(\psi_{2} \right)} & - k_{p2} & k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} \cos{\left(\alpha_{r} \right)} & - k_{r2} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{2} \right)} & - k_{r2} \cos{\left(\alpha_{r} \right)} & - k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} \cos{\left(\alpha_{s} \right)} & - k_{s2} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{2} \right)} & - k_{s2} \cos{\left(\alpha_{s} \right)} & 0 & 0 & 0 & - k_{r2} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s2} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & k_{p2} + k_{r2} \cos^{2}{\left(\alpha_{r} \right)} + k_{s2} \cos^{2}{\left(\alpha_{s} \right)} & k_{r2} \cos{\left(\alpha_{r} \right)} - k_{s2} \cos{\left(\alpha_{s} \right)} & 0 & 0 & 0\\0 & 0 & 0 & k_{r2} \sin{\left(\alpha_{r} + \psi_{2} \right)} & - k_{r2} \cos{\left(\alpha_{r} + \psi_{2} \right)} & - k_{r2} & k_{s2} \sin{\left(\alpha_{s} - \psi_{2} \right)} & k_{s2} \cos{\left(\alpha_{s} - \psi_{2} \right)} & k_{s2} & 0 & 0 & 0 & - k_{r2} \sin{\left(\alpha_{r} \right)} - k_{s2} \sin{\left(\alpha_{s} \right)} & k_{r2} \cos{\left(\alpha_{r} \right)} - k_{s2} \cos{\left(\alpha_{s} \right)} & k_{r2} + k_{s2} & 0 & 0 & 0\\- k_{p3} \cos{\left(\psi_{3} \right)} & - k_{p3} \sin{\left(\psi_{3} \right)} & 0 & - k_{r3} \sin{\left(\alpha_{r} \right)} \sin{\left(\alpha_{r} + \psi_{3} \right)} & k_{r3} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & k_{r3} \sin{\left(\alpha_{r} \right)} & - k_{s3} \sin{\left(\alpha_{s} \right)} \sin{\left(\alpha_{s} - \psi_{3} \right)} & - k_{s3} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & - k_{s3} \sin{\left(\alpha_{s} \right)} & 0 & 0 & 0 & 0 & 0 & 0 & k_{p3} + k_{r3} \sin^{2}{\left(\alpha_{r} \right)} + k_{s3} \sin^{2}{\left(\alpha_{s} \right)} & - k_{r3} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s3} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & - k_{r3} \sin{\left(\alpha_{r} \right)} - k_{s3} \sin{\left(\alpha_{s} \right)}\\k_{p3} \sin{\left(\psi_{3} \right)} & - k_{p3} \cos{\left(\psi_{3} \right)} & - k_{p3} & k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} \cos{\left(\alpha_{r} \right)} & - k_{r3} \cos{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r3} \cos{\left(\alpha_{r} \right)} & - k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} \cos{\left(\alpha_{s} \right)} & - k_{s3} \cos{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} - \psi_{3} \right)} & - k_{s3} \cos{\left(\alpha_{s} \right)} & 0 & 0 & 0 & 0 & 0 & 0 & - k_{r3} \sin{\left(\alpha_{r} \right)} \cos{\left(\alpha_{r} \right)} + k_{s3} \sin{\left(\alpha_{s} \right)} \cos{\left(\alpha_{s} \right)} & k_{p3} + k_{r3} \cos^{2}{\left(\alpha_{r} \right)} + k_{s3} \cos^{2}{\left(\alpha_{s} \right)} & k_{r3} \cos{\left(\alpha_{r} \right)} - k_{s3} \cos{\left(\alpha_{s} \right)}\\0 & 0 & 0 & k_{r3} \sin{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r3} \cos{\left(\alpha_{r} + \psi_{3} \right)} & - k_{r3} & k_{s3} \sin{\left(\alpha_{s} - \psi_{3} \right)} & k_{s3} \cos{\left(\alpha_{s} - \psi_{3} \right)} & k_{s3} & 0 & 0 & 0 & 0 & 0 & 0 & - k_{r3} \sin{\left(\alpha_{r} \right)} - k_{s3} \sin{\left(\alpha_{s} \right)} & k_{r3} \cos{\left(\alpha_{r} \right)} - k_{s3} \cos{\left(\alpha_{s} \right)} & k_{r3} + k_{s3}\end{array}\right]$

The following symplifying assumptions:
* the pressure angles of sun and ring gears are equal, i.e. $\alpha_s = \alpha_r = \alpha_n$
* the mesh stiffness for the $N$ sun-planet pairs are equal, the same happens for the $N$ ring-planet pairs
* the planet gears are cyclically symmetric, withe symmetry angle: $\psi = 2\pi/N$ and $\psi_j = (j - 1) \psi$

```python
def assumptions(A):
    A = A.subs([(symb('alpha', v), symb('alpha', 'n')) for v in [r, s]])
    A = A.subs([(k_sub(r, v + 1), symb('k', r)) for v in range(N)])
    A = A.subs([(k_sub(s, v + 1), symb('k', s)) for v in range(N)])
    A = A.subs([(k_sub(p, v + 1), symb('k', p)) for v in range(N)])
    A = A.subs([(symb(psi, v + 1), v*psi) for v in range(N)])

    return A

K_m = assumptions(K_m)
K_m
```

$\displaystyle \left[\begin{array}{cccccccccccccccccc}3 k_{p} & 0 & - k_{p} \sin{\left(\psi \right)} - k_{p} \sin{\left(2 \psi \right)} & 0 & 0 & 0 & 0 & 0 & 0 & - k_{p} & 0 & 0 & - k_{p} \cos{\left(\psi \right)} & k_{p} \sin{\left(\psi \right)} & 0 & - k_{p} \cos{\left(2 \psi \right)} & k_{p} \sin{\left(2 \psi \right)} & 0\\0 & 3 k_{p} & k_{p} \cos{\left(\psi \right)} + k_{p} \cos{\left(2 \psi \right)} + k_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - k_{p} & 0 & - k_{p} \sin{\left(\psi \right)} & - k_{p} \cos{\left(\psi \right)} & 0 & - k_{p} \sin{\left(2 \psi \right)} & - k_{p} \cos{\left(2 \psi \right)} & 0\\- k_{p} \sin{\left(\psi \right)} - k_{p} \sin{\left(2 \psi \right)} & k_{p} \cos{\left(\psi \right)} + k_{p} \cos{\left(2 \psi \right)} + k_{p} & 3 k_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - k_{p} & 0 & 0 & - k_{p} & 0 & 0 & - k_{p} & 0\\0 & 0 & 0 & k_{r} \sin^{2}{\left(\alpha_{n} \right)} + k_{r} \sin^{2}{\left(\alpha_{n} + \psi \right)} + k_{r} \sin^{2}{\left(\alpha_{n} + 2 \psi \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} - k_{r} \sin{\left(\alpha_{n} + \psi \right)} \cos{\left(\alpha_{n} + \psi \right)} - k_{r} \sin{\left(\alpha_{n} + 2 \psi \right)} \cos{\left(\alpha_{n} + 2 \psi \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} - k_{r} \sin{\left(\alpha_{n} + \psi \right)} - k_{r} \sin{\left(\alpha_{n} + 2 \psi \right)} & 0 & 0 & 0 & - k_{r} \sin^{2}{\left(\alpha_{n} \right)} & k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{r} \sin{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} + \psi \right)} & k_{r} \sin{\left(\alpha_{n} + \psi \right)} \cos{\left(\alpha_{n} \right)} & k_{r} \sin{\left(\alpha_{n} + \psi \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} + 2 \psi \right)} & k_{r} \sin{\left(\alpha_{n} + 2 \psi \right)} \cos{\left(\alpha_{n} \right)} & k_{r} \sin{\left(\alpha_{n} + 2 \psi \right)}\\0 & 0 & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} - k_{r} \sin{\left(\alpha_{n} + \psi \right)} \cos{\left(\alpha_{n} + \psi \right)} - k_{r} \sin{\left(\alpha_{n} + 2 \psi \right)} \cos{\left(\alpha_{n} + 2 \psi \right)} & k_{r} \cos^{2}{\left(\alpha_{n} \right)} + k_{r} \cos^{2}{\left(\alpha_{n} + \psi \right)} + k_{r} \cos^{2}{\left(\alpha_{n} + 2 \psi \right)} & k_{r} \cos{\left(\alpha_{n} \right)} + k_{r} \cos{\left(\alpha_{n} + \psi \right)} + k_{r} \cos{\left(\alpha_{n} + 2 \psi \right)} & 0 & 0 & 0 & k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{r} \cos^{2}{\left(\alpha_{n} \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} & k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} + \psi \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} + \psi \right)} & - k_{r} \cos{\left(\alpha_{n} + \psi \right)} & k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} + 2 \psi \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} + 2 \psi \right)} & - k_{r} \cos{\left(\alpha_{n} + 2 \psi \right)}\\0 & 0 & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} - k_{r} \sin{\left(\alpha_{n} + \psi \right)} - k_{r} \sin{\left(\alpha_{n} + 2 \psi \right)} & k_{r} \cos{\left(\alpha_{n} \right)} + k_{r} \cos{\left(\alpha_{n} + \psi \right)} + k_{r} \cos{\left(\alpha_{n} + 2 \psi \right)} & 3 k_{r} & 0 & 0 & 0 & k_{r} \sin{\left(\alpha_{n} \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} & - k_{r} & k_{r} \sin{\left(\alpha_{n} \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} & - k_{r} & k_{r} \sin{\left(\alpha_{n} \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} & - k_{r}\\0 & 0 & 0 & 0 & 0 & 0 & k_{s} \sin^{2}{\left(\alpha_{n} \right)} + k_{s} \sin^{2}{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin^{2}{\left(\alpha_{n} - \psi \right)} & k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} \sin{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{s} \sin{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} \right)} & k_{s} \sin{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} \right)} & k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)}\\0 & 0 & 0 & 0 & 0 & 0 & k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} \cos^{2}{\left(\alpha_{n} \right)} + k_{s} \cos^{2}{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \cos^{2}{\left(\alpha_{n} - \psi \right)} & k_{s} \cos{\left(\alpha_{n} \right)} + k_{s} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \cos^{2}{\left(\alpha_{n} \right)} & k_{s} \cos{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} & k_{s} \cos{\left(\alpha_{n} - 2 \psi \right)}\\0 & 0 & 0 & 0 & 0 & 0 & k_{s} \sin{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)} & k_{s} \cos{\left(\alpha_{n} \right)} + k_{s} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \cos{\left(\alpha_{n} - \psi \right)} & 3 k_{s} & - k_{s} \sin{\left(\alpha_{n} \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} & k_{s} & - k_{s} \sin{\left(\alpha_{n} \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} & k_{s} & - k_{s} \sin{\left(\alpha_{n} \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} & k_{s}\\- k_{p} & 0 & 0 & - k_{r} \sin^{2}{\left(\alpha_{n} \right)} & k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{r} \sin{\left(\alpha_{n} \right)} & - k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} & k_{p} + k_{r} \sin^{2}{\left(\alpha_{n} \right)} + k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)} & 0 & 0 & 0 & 0 & 0 & 0\\0 & - k_{p} & - k_{p} & k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{r} \cos^{2}{\left(\alpha_{n} \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \cos^{2}{\left(\alpha_{n} \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{p} + k_{r} \cos^{2}{\left(\alpha_{n} \right)} + k_{s} \cos^{2}{\left(\alpha_{n} \right)} & k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & k_{r} \sin{\left(\alpha_{n} \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} & - k_{r} & k_{s} \sin{\left(\alpha_{n} \right)} & k_{s} \cos{\left(\alpha_{n} \right)} & k_{s} & - k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)} & k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)} & k_{r} + k_{s} & 0 & 0 & 0 & 0 & 0 & 0\\- k_{p} \cos{\left(\psi \right)} & - k_{p} \sin{\left(\psi \right)} & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} + \psi \right)} & k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} + \psi \right)} & k_{r} \sin{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} & 0 & 0 & 0 & k_{p} + k_{r} \sin^{2}{\left(\alpha_{n} \right)} + k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)} & 0 & 0 & 0\\k_{p} \sin{\left(\psi \right)} & - k_{p} \cos{\left(\psi \right)} & - k_{p} & k_{r} \sin{\left(\alpha_{n} + \psi \right)} \cos{\left(\alpha_{n} \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} + \psi \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} & 0 & 0 & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{p} + k_{r} \cos^{2}{\left(\alpha_{n} \right)} + k_{s} \cos^{2}{\left(\alpha_{n} \right)} & k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)} & 0 & 0 & 0\\0 & 0 & 0 & k_{r} \sin{\left(\alpha_{n} + \psi \right)} & - k_{r} \cos{\left(\alpha_{n} + \psi \right)} & - k_{r} & k_{s} \sin{\left(\alpha_{n} - \psi \right)} & k_{s} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} & 0 & 0 & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)} & k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)} & k_{r} + k_{s} & 0 & 0 & 0\\- k_{p} \cos{\left(2 \psi \right)} & - k_{p} \sin{\left(2 \psi \right)} & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} + 2 \psi \right)} & k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} + 2 \psi \right)} & k_{r} \sin{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} & 0 & 0 & 0 & 0 & 0 & 0 & k_{p} + k_{r} \sin^{2}{\left(\alpha_{n} \right)} + k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)}\\k_{p} \sin{\left(2 \psi \right)} & - k_{p} \cos{\left(2 \psi \right)} & - k_{p} & k_{r} \sin{\left(\alpha_{n} + 2 \psi \right)} \cos{\left(\alpha_{n} \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} + 2 \psi \right)} & - k_{r} \cos{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} & 0 & 0 & 0 & 0 & 0 & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{p} + k_{r} \cos^{2}{\left(\alpha_{n} \right)} + k_{s} \cos^{2}{\left(\alpha_{n} \right)} & k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)}\\0 & 0 & 0 & k_{r} \sin{\left(\alpha_{n} + 2 \psi \right)} & - k_{r} \cos{\left(\alpha_{n} + 2 \psi \right)} & - k_{r} & k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} & k_{s} \cos{\left(\alpha_{n} - 2 \psi \right)} & k_{s} & 0 & 0 & 0 & 0 & 0 & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)} & k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)} & k_{r} + k_{s}\end{array}\right]$

## Remove DOFs associated to the ring dynamics

```python
for idx in range(3):
    q.row_del(3)
    M.row_del(3)
    M.col_del(3)
    G.row_del(3)
    G.col_del(3)
    K_omega.row_del(3)
    K_omega.col_del(3)
    K_b.row_del(3)
    K_b.col_del(3)
    K_m.row_del(3)
    K_m.col_del(3)

coeff_list.remove(r)
N_DOF = N_DOF - 3
```

## Coordinate transformation:

First from translational to torsional coordinates, them making the sun DOF to be the last one, making it easier to assemble a multi-stage gearbox.

```python
func = lambda x: diag(1, 1, symb(r, x))
R_1 = diag(*[[func(v)] for v in coeff_list])
R_1
```

$\displaystyle \left[\begin{array}{ccccccccccccccc}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & r_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & r_{s} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & r_{p} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & r_{p} & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & r_{p}\end{array}\right]$

```python
N3 = N_DOF - 3
I3 = eye(3)

R_2 = zeros(N_DOF)
R_2[0:3,  0:3 ] = I3
R_2[3:6, N3:  ] = I3
R_2[6: ,  3:N3] = eye(3*N)
R_2
```

$\displaystyle \left[\begin{array}{ccccccccccccccc}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\end{array}\right]$

```python
R = R_1*R_2
RMR = lambda m: transpose(R)*m*R
R
```

$\displaystyle \left[\begin{array}{ccccccccccccccc}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & r_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & r_{s}\\0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & r_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & r_{p} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & r_{p} & 0 & 0 & 0\end{array}\right]$

### Inertia matrix

```python
M = RMR(M)

if(not M.is_symmetric()):
    print('error in M matrix')
M
```

$\displaystyle \left[\begin{array}{ccccccccccccccc}m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & I_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & I_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & I_{p} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & I_{p} & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & I_{s}\end{array}\right]$

### Gyroscopic matrix

```python
G = RMR(G)
G
```

$\displaystyle \left[\begin{array}{ccccccccccccccc}0 & - 2 m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & - 2 m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 2 m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & - 2 m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 2 m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - 2 m_{p} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 m_{p} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - 2 m_{s} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 m_{s} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right]$

### Centripetal stiffness matrix:

```python
K_omega = RMR(K_omega)

if(not K_omega.is_symmetric()):
    print('error in K_omega matrix')
K_omega
```

$\displaystyle \left[\begin{array}{ccccccccccccccc}m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{p} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right]$

### Bearing stiffness

```python
K_b = RMR(K_b)

if(not K_b.is_symmetric()):
    print('error in K_b matrix')
K_b
```

$\displaystyle \left[\begin{array}{ccccccccccccccc}k_{cx} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & k_{cy} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & k_{sx} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & k_{sy} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right]$

### Mesh stiffness matrix

```python
K_m = RMR(K_m)

if(not K_m.is_symmetric()):
    print('error in K_m matrix')
K_m
```

$\displaystyle \left[\begin{array}{ccccccccccccccc}3 k_{p} & 0 & r_{c} \left(- k_{p} \sin{\left(\psi \right)} - k_{p} \sin{\left(2 \psi \right)}\right) & - k_{p} & 0 & 0 & - k_{p} \cos{\left(\psi \right)} & k_{p} \sin{\left(\psi \right)} & 0 & - k_{p} \cos{\left(2 \psi \right)} & k_{p} \sin{\left(2 \psi \right)} & 0 & 0 & 0 & 0\\0 & 3 k_{p} & r_{c} \left(k_{p} \cos{\left(\psi \right)} + k_{p} \cos{\left(2 \psi \right)} + k_{p}\right) & 0 & - k_{p} & 0 & - k_{p} \sin{\left(\psi \right)} & - k_{p} \cos{\left(\psi \right)} & 0 & - k_{p} \sin{\left(2 \psi \right)} & - k_{p} \cos{\left(2 \psi \right)} & 0 & 0 & 0 & 0\\r_{c} \left(- k_{p} \sin{\left(\psi \right)} - k_{p} \sin{\left(2 \psi \right)}\right) & r_{c} \left(k_{p} \cos{\left(\psi \right)} + k_{p} \cos{\left(2 \psi \right)} + k_{p}\right) & 3 k_{p} r_{c}^{2} & 0 & - k_{p} r_{c} & 0 & 0 & - k_{p} r_{c} & 0 & 0 & - k_{p} r_{c} & 0 & 0 & 0 & 0\\- k_{p} & 0 & 0 & k_{p} + k_{r} \sin^{2}{\left(\alpha_{n} \right)} + k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & r_{p} \left(- k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)}\right) & 0 & 0 & 0 & 0 & 0 & 0 & - k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} r_{s} \sin{\left(\alpha_{n} \right)}\\0 & - k_{p} & - k_{p} r_{c} & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{p} + k_{r} \cos^{2}{\left(\alpha_{n} \right)} + k_{s} \cos^{2}{\left(\alpha_{n} \right)} & r_{p} \left(k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)}\right) & 0 & 0 & 0 & 0 & 0 & 0 & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \cos^{2}{\left(\alpha_{n} \right)} & - k_{s} r_{s} \cos{\left(\alpha_{n} \right)}\\0 & 0 & 0 & r_{p} \left(- k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)}\right) & r_{p} \left(k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)}\right) & r_{p}^{2} \left(k_{r} + k_{s}\right) & 0 & 0 & 0 & 0 & 0 & 0 & k_{s} r_{p} \sin{\left(\alpha_{n} \right)} & k_{s} r_{p} \cos{\left(\alpha_{n} \right)} & k_{s} r_{p} r_{s}\\- k_{p} \cos{\left(\psi \right)} & - k_{p} \sin{\left(\psi \right)} & 0 & 0 & 0 & 0 & k_{p} + k_{r} \sin^{2}{\left(\alpha_{n} \right)} + k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & r_{p} \left(- k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)}\right) & 0 & 0 & 0 & - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} r_{s} \sin{\left(\alpha_{n} \right)}\\k_{p} \sin{\left(\psi \right)} & - k_{p} \cos{\left(\psi \right)} & - k_{p} r_{c} & 0 & 0 & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{p} + k_{r} \cos^{2}{\left(\alpha_{n} \right)} + k_{s} \cos^{2}{\left(\alpha_{n} \right)} & r_{p} \left(k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)}\right) & 0 & 0 & 0 & - k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} r_{s} \cos{\left(\alpha_{n} \right)}\\0 & 0 & 0 & 0 & 0 & 0 & r_{p} \left(- k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)}\right) & r_{p} \left(k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)}\right) & r_{p}^{2} \left(k_{r} + k_{s}\right) & 0 & 0 & 0 & k_{s} r_{p} \sin{\left(\alpha_{n} - \psi \right)} & k_{s} r_{p} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} r_{p} r_{s}\\- k_{p} \cos{\left(2 \psi \right)} & - k_{p} \sin{\left(2 \psi \right)} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & k_{p} + k_{r} \sin^{2}{\left(\alpha_{n} \right)} + k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & r_{p} \left(- k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)}\right) & - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} r_{s} \sin{\left(\alpha_{n} \right)}\\k_{p} \sin{\left(2 \psi \right)} & - k_{p} \cos{\left(2 \psi \right)} & - k_{p} r_{c} & 0 & 0 & 0 & 0 & 0 & 0 & - k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{p} + k_{r} \cos^{2}{\left(\alpha_{n} \right)} + k_{s} \cos^{2}{\left(\alpha_{n} \right)} & r_{p} \left(k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)}\right) & - k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} r_{s} \cos{\left(\alpha_{n} \right)}\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & r_{p} \left(- k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)}\right) & r_{p} \left(k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)}\right) & r_{p}^{2} \left(k_{r} + k_{s}\right) & k_{s} r_{p} \sin{\left(\alpha_{n} - 2 \psi \right)} & k_{s} r_{p} \cos{\left(\alpha_{n} - 2 \psi \right)} & k_{s} r_{p} r_{s}\\0 & 0 & 0 & - k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{s} r_{p} \sin{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} \right)} & k_{s} r_{p} \sin{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} \right)} & k_{s} r_{p} \sin{\left(\alpha_{n} - 2 \psi \right)} & k_{s} \sin^{2}{\left(\alpha_{n} \right)} + k_{s} \sin^{2}{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin^{2}{\left(\alpha_{n} - \psi \right)} & k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} - \psi \right)} & r_{s} \left(k_{s} \sin{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)}\right)\\0 & 0 & 0 & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \cos^{2}{\left(\alpha_{n} \right)} & k_{s} r_{p} \cos{\left(\alpha_{n} \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} r_{p} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} & - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} & k_{s} r_{p} \cos{\left(\alpha_{n} - 2 \psi \right)} & k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} \cos^{2}{\left(\alpha_{n} \right)} + k_{s} \cos^{2}{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \cos^{2}{\left(\alpha_{n} - \psi \right)} & r_{s} \left(k_{s} \cos{\left(\alpha_{n} \right)} + k_{s} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \cos{\left(\alpha_{n} - \psi \right)}\right)\\0 & 0 & 0 & - k_{s} r_{s} \sin{\left(\alpha_{n} \right)} & - k_{s} r_{s} \cos{\left(\alpha_{n} \right)} & k_{s} r_{p} r_{s} & - k_{s} r_{s} \sin{\left(\alpha_{n} \right)} & - k_{s} r_{s} \cos{\left(\alpha_{n} \right)} & k_{s} r_{p} r_{s} & - k_{s} r_{s} \sin{\left(\alpha_{n} \right)} & - k_{s} r_{s} \cos{\left(\alpha_{n} \right)} & k_{s} r_{p} r_{s} & r_{s} \left(k_{s} \sin{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)}\right) & r_{s} \left(k_{s} \cos{\left(\alpha_{n} \right)} + k_{s} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \cos{\left(\alpha_{n} - \psi \right)}\right) & 3 k_{s} r_{s}^{2}\end{array}\right]$

From that, one can write the matrices for a planetary system with $n$-planets using the following code:

```python
# inertia matrix:
func = lambda x: diag(symb('m', x), symb('m', x), symb('I', x))
list_tmp = coeff_list
list_tmp.append(list_tmp.pop(list_tmp.index(s)))
M_p = diag(*[[func(v)] for v in list_tmp], unpack = True)

mat_diff = abs(matrix2numpy(simplify(M_p - M))).sum()

if(mat_diff != 0.0):
    print('Error in M matrix.')

# gyroscopic matrix:
func = lambda x: Matrix(3, 3, [0, -2*symb('m', x), 0, 2*symb('m', x), 0, 0, 0, 0, 0])
G_p = diag(*[[func(v)] for v in list_tmp], unpack = True)

mat_diff = abs(matrix2numpy(simplify(G_p - G))).sum()

if(mat_diff != 0.0):
    print('Error in G matrix.')

# centripetal stiffness matrix
func = lambda x: diag(symb('m', x), symb('m', x), 0)
K_omega_p = diag(*[[func(v)] for v in list_tmp], unpack = True)

mat_diff = abs(matrix2numpy(simplify(K_omega_p - K_omega))).sum()

if(mat_diff != 0.0):
    print('Error in K_omega matrix.')

# bearing stiffness matrix:
func = lambda z: diag(k_sub(z, 'x'), k_sub(z, 'y'), 0) if(z != p) else zeros(3)
K_b_p = diag(*[[func(v)] for v in coeff_list])

mat_diff = abs(matrix2numpy(simplify(K_b_p - K_b))).sum()

if(mat_diff != 0.0):
    print('Error in K_b matrix.')
```

For the mesh stiffness matrix it is easier to work with the sub matrices and the coordinate transformation matrices $R_2$ and $R_1$ in the following way:

```python
kc1, kr1, ks1, kpp = symbols('Sum_k_c1 Sum_k_r1 Sum_k_s1 k_pp', type = float)
kc2, kr2, ks2      = symbols('k_c2 k_r2 k_s2', type = float)

d1 = diag(kc1, kr1, ks1)
d2 = diag(*[symb(kpp, n + 1) for n in range(N)])
od = Matrix([[symb(kc2, idx + 1) for idx in range(N)],
             [symb(kr2, idx + 1) for idx in range(N)],
             [symb(ks2, idx + 1) for idx in range(N)]])

k_ov = BlockMatrix([[          d1 , od],
                    [transpose(od), d2]])
k_ov = Matrix(k_ov)
k_ov.row_del(1)
k_ov.col_del(1)

R1 = diag(*[symb('r', 'c'), symb('r', 's'), *[symb('r', 'p') for idx in range(N)]])

R2 = zeros(N + 2, N + 2)
R2[0, 0] = 1
R2[1, N + 1] = 1
for idx in range(2, N + 2):
    R2[idx, idx - 1] = 1

R12 = R1*R2
k_ov = transpose(R12)*k_ov*R12
k_ov
```

$\displaystyle \left[\begin{matrix}Sum_{k c1} r_{c}^{2} & k_{c2 1} r_{c} r_{p} & k_{c2 2} r_{c} r_{p} & k_{c2 3} r_{c} r_{p} & 0\\k_{c2 1} r_{c} r_{p} & k_{pp 1} r_{p}^{2} & 0 & 0 & k_{s2 1} r_{p} r_{s}\\k_{c2 2} r_{c} r_{p} & 0 & k_{pp 2} r_{p}^{2} & 0 & k_{s2 2} r_{p} r_{s}\\k_{c2 3} r_{c} r_{p} & 0 & 0 & k_{pp 3} r_{p}^{2} & k_{s2 3} r_{p} r_{s}\\0 & k_{s2 1} r_{p} r_{s} & k_{s2 2} r_{p} r_{s} & k_{s2 3} r_{p} r_{s} & Sum_{k s1} r_{s}^{2}\end{matrix}\right]$

```python
func = lambda x: diag(1, 1, symb(r, x))
fMf = lambda x, y, z: transpose(func(y))*x*func(z)

K_m_p = zeros(N_DOF)
K_m_p[ 0:3 , 0:3 ] = fMf(sum_Kc1, c, c)
K_m_p[ 0:3 , 3:N3] =           Matrix(BlockMatrix([[fMf(K_c2(idx + 1), c, p) for idx in range(N)]]))
K_m_p[ 3:N3, 0:3 ] = transpose(Matrix(BlockMatrix([[fMf(K_c2(idx + 1), c, p) for idx in range(N)]])))
K_m_p[N3:  , 3:N3] =           Matrix(BlockMatrix([[fMf(K_s2(idx + 1), s, p) for idx in range(N)]]))
K_m_p[ 3:N3, N3: ] = transpose(Matrix(BlockMatrix([[fMf(K_s2(idx + 1), s, p) for idx in range(N)]])))
K_m_p[ 3:N3, 3:N3] = diag(*[fMf(K_pp(idx + 1), p, p) for idx in range(N)])
K_m_p[N3:  , N3: ] = fMf(sum_Ks1, s, s)

K_m_p = assumptions(K_m_p)

mat_diff = abs(matrix2numpy(simplify(K_m_p - K_m))).sum()

if(mat_diff != 0.0):
    print('Error in K_m matrix.')
```

## Combining planet DOFs

```python
C = zeros(N_DOF, 9)

C[ 0:3 , 0:3] = I3
C[N3:  , 6: ] = I3
C[ 3:N3, 3:6] = Matrix([I3 for idx in range(N)])

CMC = lambda m: transpose(C)*m*C
```

### Inertia matrix

```python
M_C = CMC(M)

if(not M_C.is_symmetric()):
    print('error in M_C matrix')
M_C
```

$\displaystyle \left[\begin{matrix}m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & I_{c} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 3 m_{p} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 3 m_{p} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 3 I_{p} & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & I_{s}\end{matrix}\right]$

### Gyroscopic matrix

```python
G_C = CMC(G)
G_C
```

$\displaystyle \left[\begin{matrix}0 & - 2 m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & - 6 m_{p} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 6 m_{p} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & - 2 m_{s} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 2 m_{s} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$

### Centripetal stiffness matrix

```python
K_omega_C = CMC(K_omega)
if(not K_omega_C.is_symmetric()):
    print('error in K_omega_C matrix')
K_omega_C
```

$\displaystyle \left[\begin{matrix}m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & m_{c} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 3 m_{p} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 3 m_{p} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & m_{s} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$

### Bearing stiffness matrix

```python
K_b_C = CMC(K_b)

if(not K_b_C.is_symmetric()):
    print('error in K_b_C matrix')
K_b_C
```

$\displaystyle \left[\begin{matrix}k_{cx} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & k_{cy} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & k_{sx} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & k_{sy} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$

### Mesh stiffness matrix

```python
K_m_C = CMC(K_m)

if(not K_m_C.is_symmetric()):
    print('error in K_m_C matrix')

K_m_C
```

$\displaystyle \left[\begin{matrix}3 k_{p} & 0 & r_{c} \left(- k_{p} \sin{\left(\psi \right)} - k_{p} \sin{\left(2 \psi \right)}\right) & - k_{p} \cos{\left(\psi \right)} - k_{p} \cos{\left(2 \psi \right)} - k_{p} & k_{p} \sin{\left(\psi \right)} + k_{p} \sin{\left(2 \psi \right)} & 0 & 0 & 0 & 0\\0 & 3 k_{p} & r_{c} \left(k_{p} \cos{\left(\psi \right)} + k_{p} \cos{\left(2 \psi \right)} + k_{p}\right) & - k_{p} \sin{\left(\psi \right)} - k_{p} \sin{\left(2 \psi \right)} & - k_{p} \cos{\left(\psi \right)} - k_{p} \cos{\left(2 \psi \right)} - k_{p} & 0 & 0 & 0 & 0\\r_{c} \left(- k_{p} \sin{\left(\psi \right)} - k_{p} \sin{\left(2 \psi \right)}\right) & r_{c} \left(k_{p} \cos{\left(\psi \right)} + k_{p} \cos{\left(2 \psi \right)} + k_{p}\right) & 3 k_{p} r_{c}^{2} & 0 & - 3 k_{p} r_{c} & 0 & 0 & 0 & 0\\- k_{p} \cos{\left(\psi \right)} - k_{p} \cos{\left(2 \psi \right)} - k_{p} & - k_{p} \sin{\left(\psi \right)} - k_{p} \sin{\left(2 \psi \right)} & 0 & 3 k_{p} + 3 k_{r} \sin^{2}{\left(\alpha_{n} \right)} + 3 k_{s} \sin^{2}{\left(\alpha_{n} \right)} & - 3 k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + 3 k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & 3 r_{p} \left(- k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)}\right) & - k_{s} \sin^{2}{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - 2 \psi \right)} - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & - 3 k_{s} r_{s} \sin{\left(\alpha_{n} \right)}\\k_{p} \sin{\left(\psi \right)} + k_{p} \sin{\left(2 \psi \right)} & - k_{p} \cos{\left(\psi \right)} - k_{p} \cos{\left(2 \psi \right)} - k_{p} & - 3 k_{p} r_{c} & - 3 k_{r} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + 3 k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & 3 k_{p} + 3 k_{r} \cos^{2}{\left(\alpha_{n} \right)} + 3 k_{s} \cos^{2}{\left(\alpha_{n} \right)} & 3 r_{p} \left(k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)}\right) & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} \right)} & - k_{s} \cos^{2}{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & - 3 k_{s} r_{s} \cos{\left(\alpha_{n} \right)}\\0 & 0 & 0 & 3 r_{p} \left(- k_{r} \sin{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)}\right) & 3 r_{p} \left(k_{r} \cos{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)}\right) & 3 r_{p}^{2} \left(k_{r} + k_{s}\right) & k_{s} r_{p} \sin{\left(\alpha_{n} \right)} + k_{s} r_{p} \sin{\left(\alpha_{n} - 2 \psi \right)} + k_{s} r_{p} \sin{\left(\alpha_{n} - \psi \right)} & k_{s} r_{p} \cos{\left(\alpha_{n} \right)} + k_{s} r_{p} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} r_{p} \cos{\left(\alpha_{n} - \psi \right)} & 3 k_{s} r_{p} r_{s}\\0 & 0 & 0 & - k_{s} \sin^{2}{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - 2 \psi \right)} - k_{s} \sin{\left(\alpha_{n} \right)} \sin{\left(\alpha_{n} - \psi \right)} & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} \right)} & k_{s} r_{p} \sin{\left(\alpha_{n} \right)} + k_{s} r_{p} \sin{\left(\alpha_{n} - 2 \psi \right)} + k_{s} r_{p} \sin{\left(\alpha_{n} - \psi \right)} & k_{s} \sin^{2}{\left(\alpha_{n} \right)} + k_{s} \sin^{2}{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin^{2}{\left(\alpha_{n} - \psi \right)} & k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} - \psi \right)} & r_{s} \left(k_{s} \sin{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)}\right)\\0 & 0 & 0 & - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} - k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & - k_{s} \cos^{2}{\left(\alpha_{n} \right)} - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} - k_{s} \cos{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} r_{p} \cos{\left(\alpha_{n} \right)} + k_{s} r_{p} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} r_{p} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)} \cos{\left(\alpha_{n} - \psi \right)} & k_{s} \cos^{2}{\left(\alpha_{n} \right)} + k_{s} \cos^{2}{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \cos^{2}{\left(\alpha_{n} - \psi \right)} & r_{s} \left(k_{s} \cos{\left(\alpha_{n} \right)} + k_{s} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \cos{\left(\alpha_{n} - \psi \right)}\right)\\0 & 0 & 0 & - 3 k_{s} r_{s} \sin{\left(\alpha_{n} \right)} & - 3 k_{s} r_{s} \cos{\left(\alpha_{n} \right)} & 3 k_{s} r_{p} r_{s} & r_{s} \left(k_{s} \sin{\left(\alpha_{n} \right)} + k_{s} \sin{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \sin{\left(\alpha_{n} - \psi \right)}\right) & r_{s} \left(k_{s} \cos{\left(\alpha_{n} \right)} + k_{s} \cos{\left(\alpha_{n} - 2 \psi \right)} + k_{s} \cos{\left(\alpha_{n} - \psi \right)}\right) & 3 k_{s} r_{s}^{2}\end{matrix}\right]$

## Adapting it to a parallel gear set

Considering only one of the sun-planets pairs, one should change the sub-indexes in the following way:
* [p]lanet => [w]heel
* [s]un    => [p]inion;
It also necessary to remove the mesh stiffness of the ring-planet pair
### Inertia matrix

```python
N6 = N_DOF - 6
m_w, m_p, I_w, I_p, m_s, I_s = symbols('m_w m_p I_w I_p m_s I_s', type = float)

M_par = M[N6:, N6:]
M_par = M_par.subs([(m_p, m_w), (m_s, m_p),
                    (I_p, I_w), (I_s, I_p)])
M_par
```

$\displaystyle \left[\begin{matrix}m_{w} & 0 & 0 & 0 & 0 & 0\\0 & m_{w} & 0 & 0 & 0 & 0\\0 & 0 & I_{w} & 0 & 0 & 0\\0 & 0 & 0 & m_{p} & 0 & 0\\0 & 0 & 0 & 0 & m_{p} & 0\\0 & 0 & 0 & 0 & 0 & I_{p}\end{matrix}\right]$

### Gyroscopic matrix

```python
G_par = G[N6:, N6:]
G_par = G_par.subs([(m_p, m_w), (m_s, m_p)])
G_par
```

$\displaystyle \left[\begin{matrix}0 & - 2 m_{w} & 0 & 0 & 0 & 0\\2 m_{w} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & - 2 m_{p} & 0\\0 & 0 & 0 & 2 m_{p} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$

### Centripetal stiffness matrix

```python
K_omega_par = K_omega[N6:, N6:]
K_omega_par = K_omega_par.subs([(m_p, m_w), (m_s, m_p)])
K_omega_par
```

$\displaystyle \left[\begin{matrix}m_{w} & 0 & 0 & 0 & 0 & 0\\0 & m_{w} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & m_{p} & 0 & 0\\0 & 0 & 0 & 0 & m_{p} & 0\\0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$

### Bearing stiffness matrix
In this case, one should use the carrier instead of the planet.

```python
K_b_par = zeros(6)
K_b_par[0:3,0:3] = K_b[ 0:3,  0:3]
K_b_par[3:6,3:6] = K_b[N3: , N3: ]

K_b_par = K_b_par.subs([(k_sub(c, v), k_sub('w', v)) for v in ['x', 'y']])
K_b_par = K_b_par.subs([(k_sub(s, v), k_sub('p', v)) for v in ['x', 'y']])
K_b_par
```

$\displaystyle \left[\begin{matrix}k_{wx} & 0 & 0 & 0 & 0 & 0\\0 & k_{wy} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & k_{px} & 0 & 0\\0 & 0 & 0 & 0 & k_{py} & 0\\0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$

### Mesh stiffness matrix
In this case one must pick-up the sub-matrices related to the first planet and the sun, instead of the last sun as in the previous matrices.

```python
K_m_par = zeros(6)
K_m_par[0:3, 0:3] = K_m[ 3:6,  3:6]
K_m_par[0:3, 3: ] = K_m[ 3:6, N3: ]
K_m_par[3: , 0:3] = K_m[N3: ,  3:6]
K_m_par[3: , 3: ] = K_m[N3: , N3: ]
#K_m_par = K_m_par.subs([(symb('k', 's'), symb('k', 's')/5), (psi, 0)])
K_m_par = K_m_par.subs([(symb('k', 'p'), symb('k', 'w')),
                        (symb('k', 's'), symb('k', 'p')),
                        (symb('r', 'p'), symb('r', 'w')),
                        (symb('r', 's'), symb('r', 'p'))])
K_m_par = K_m_par.subs([(symb('k', 'r'), 0), (psi, 0), (5*symb('k', 'p'), symb('k', 'p'))])

if(not K_m_par.is_symmetric()):
    print('error in K_m_par matrix')
K_m_par
```

$\displaystyle \left[\begin{matrix}k_{p} \sin^{2}{\left(\alpha_{n} \right)} + k_{w} & k_{p} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{p} r_{w} \sin{\left(\alpha_{n} \right)} & - k_{p} \sin^{2}{\left(\alpha_{n} \right)} & - k_{p} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{p} r_{p} \sin{\left(\alpha_{n} \right)}\\k_{p} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{p} \cos^{2}{\left(\alpha_{n} \right)} + k_{w} & - k_{p} r_{w} \cos{\left(\alpha_{n} \right)} & - k_{p} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{p} \cos^{2}{\left(\alpha_{n} \right)} & - k_{p} r_{p} \cos{\left(\alpha_{n} \right)}\\- k_{p} r_{w} \sin{\left(\alpha_{n} \right)} & - k_{p} r_{w} \cos{\left(\alpha_{n} \right)} & k_{p} r_{w}^{2} & k_{p} r_{w} \sin{\left(\alpha_{n} \right)} & k_{p} r_{w} \cos{\left(\alpha_{n} \right)} & k_{p} r_{p} r_{w}\\- k_{p} \sin^{2}{\left(\alpha_{n} \right)} & - k_{p} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & k_{p} r_{w} \sin{\left(\alpha_{n} \right)} & 3 k_{p} \sin^{2}{\left(\alpha_{n} \right)} & 3 k_{p} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & 3 k_{p} r_{p} \sin{\left(\alpha_{n} \right)}\\- k_{p} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & - k_{p} \cos^{2}{\left(\alpha_{n} \right)} & k_{p} r_{w} \cos{\left(\alpha_{n} \right)} & 3 k_{p} \sin{\left(\alpha_{n} \right)} \cos{\left(\alpha_{n} \right)} & 3 k_{p} \cos^{2}{\left(\alpha_{n} \right)} & 3 k_{p} r_{p} \cos{\left(\alpha_{n} \right)}\\- k_{p} r_{p} \sin{\left(\alpha_{n} \right)} & - k_{p} r_{p} \cos{\left(\alpha_{n} \right)} & k_{p} r_{p} r_{w} & 3 k_{p} r_{p} \sin{\left(\alpha_{n} \right)} & 3 k_{p} r_{p} \cos{\left(\alpha_{n} \right)} & 3 k_{p} r_{p}^{2}\end{matrix}\right]$