Building Quiz 07

import numpy as np
import matplotlib.pyplot as plt

plt.style.use('fivethirtyeight')

Building Quiz 07

coordinates and path of bead

A bead moves along a planar sinusoidal track. It does not rotate as it moves along the path, so the generalized coordinates are its x-position y-position, $\(\mathbf{q} = [x,~y]\)$. There are two constraints on the motion of the bead,

  • \(y = \sin x\)

  • \(x = 10 t\), where \(t\) is time in seconds.

  1. write the constraint equations, \(\mathbf{C}(\mathbf{q},~t)\).

  2. write out the Jacobian of the constraints, \(\mathbf{C_q}\)

  3. Invert the Jacobian to solve for \(\dot{x}~and~\dot{y}\), using \(\mathbf{C_q \dot{q}} = -\mathbf{C}_t\)

Numerical approach

def C(q, t):
    C = np.zeros(2)
    C[0] = np.array([q[1] - np.sin(q[0])])
    C[1] = np.array(q[0] - 10*t)
    return C
def Cq(q, t):
    Cq = np.zeros((2, 2))
    Cq[0, 0] = -np.cos(q[0])
    Cq[0, 1] = 1
    Cq[1, 0] = 1
    return Cq
Cq(np.array([0,0]), 1)
array([[-1.,  1.],
       [ 1.,  0.]])

SymPy approach

import sympy
sympy.var('x, y, t')
q = sympy.Matrix([x, y])
q
\[\begin{split}\displaystyle \left[\begin{matrix}x\\y\end{matrix}\right]\end{split}\]
C = sympy.Matrix([y - sympy.sin(x), x - 10*t])
C
\[\begin{split}\displaystyle \left[\begin{matrix}y - \sin{\left(x \right)}\\- 10 t + x\end{matrix}\right]\end{split}\]
C.jacobian(q)
\[\begin{split}\displaystyle \left[\begin{matrix}- \cos{\left(x \right)} & 1\\1 & 0\end{matrix}\right]\end{split}\]