Building Quiz 07
Contents
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
Building Quiz 07¶
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, $q=[x, y]$. There are two constraints on the motion of the bead,
y=sinx
x=10t, where t is time in seconds.
write the constraint equations, C(q, t).
write out the Jacobian of the constraints, Cq
Invert the Jacobian to solve for ˙x and ˙y, using Cq˙q=−Ct
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
[xy]
C = sympy.Matrix([y - sympy.sin(x), x - 10*t])
C
[y−sin(x)−10t+x]
C.jacobian(q)
[−cos(x)110]