Exemple #1
0
forces = [(pC1, -k * (x1.magnitude() - L_prime) * x1.normalize()),
          (pC2, -k * (x2.magnitude() - L_prime) * x2.normalize()),
          (pC3, -k * (x3.magnitude() - L_prime) * x3.normalize())]

partials = partial_velocities(zip(*forces)[0], u, X, kde_map)
Fr, _ = generalized_active_forces(partials, forces)
print('generalized active forces')
for i, fr in enumerate(Fr, 1):
    print('\nF{0} = {1}'.format(i, msprint(fr)))

# use a dummy symbol since series() does not work with dynamicsymbols
_q = Dummy('q')
series_exp = (
    lambda x, qi, n_: x.subs(qi, _q).series(_q, n=n_).removeO().subs(_q, qi))

# remove all terms order 3 or higher in qi
Fr_series = [reduce(lambda x, y: series_exp(x, y, 3), q, fr) for fr in Fr]
print('\nseries expansion of generalized active forces')
for i, fr in enumerate(Fr_series, 1):
    print('\nF{0} = {1}'.format(i, msprint(fr)))

V = potential_energy(Fr_series, q, u, kde_map)
print('\nV = {0}'.format(msprint(V)))
print('Setting C = 0, α1, α2, α3, α4, α5, α6 = 0')
V = V.subs(dict(zip(symbols('C α1 α2 α3 α4 α5 α6'), [0] * 7)))
print('V = {0}'.format(msprint(V)))

V_expected = k * a**2 / 2 * (
    (q1 - q5 - q6)**2 + (q2 - q6 - q4)**2 + (q3 - q4 - q5)**2)
assert expand(V - V_expected) == 0
Exemple #2
0
# forces
k = 5*m*g/L
r = (L_prime + L*sin(q))*N.y + (L - L*cos(q))*N.z
forces = [(pP, -m*g*N.z), (pP, -k*(r.magnitude() - L_prime)*r.normalize())]

partials = partial_velocities(zip(*forces)[0], [u], N, kde_map)
Fr, _ = generalized_active_forces(partials, forces)

# use a dummy symbol since series() does not work with dynamicsymbols
print('part a')
_q = Dummy('q')
terms = Fr[0].subs(q, _q).series(_q, n=4).removeO().subs(_q, q)
print('Using a series approximation of order 4:')
print('F1 ≈ {0}'.format(msprint(collect(terms, m*g*L))))

V = potential_energy([terms], [q], [u], kde_map)
print('V = {0}'.format(msprint(V)))
print('Setting C = 0, α1 = 0')
V = V.subs(dict(zip(symbols('C α1'), [0, 0])))
print('V = {0}'.format(msprint(collect(V, m*g*L))))

V_expected = m*g*L*(0*q + 3*q**2 + 0*q**3 + -7*q**4/8)
assert expand(V - V_expected) == 0


print('\npart b')
Fr_expected = m*g*L*(-6*q + 0*q**2 + 7*q**3/2)

print('Fr using V')
Fr_V = generalized_active_forces_V(V, [q], [u], kde_map)
print('F1_V = {0}'.format(msprint(collect(Fr_V[0], m*g*L))))
Exemple #3
0
print(('\nVerify V_γ = {0} is a potential energy '.format(V_gamma) +
       'contribution of γ for C.'))
V_gamma_dot = -sum(fr * ur for fr, ur in
                   zip(*generalized_active_forces(partials_tilde,
                                                  forces[1:])))
if V_gamma_dot == V_gamma.diff(t).subs(kde_map):
    print('d/dt(V_γ) == -sum(Fr_γ * ur).')
else:
    print('d/dt(V_γ) != -sum(Fr_γ * ur).')
    print('d/dt(V_γ) = {0}'.format(msprint(V_gamma.diff(t))))
    print('-sum(Fr_γ * ur) = {0}'.format(msprint(V_gamma_dot)))

#print('\nFinding a potential energy function V while C is rolling '
#      'without slip.')
#V = potential_energy(Fr_tilde, q, u_indep, kde_map, vc_map)
#if V is not None:
#    print('V = {0}'.format(V))

print('\nFinding a potential energy function V while C is rolling with slip.')
V = potential_energy(Fr, q, u, kde_map)
if V is not None:
    print('V = {0}'.format(V))

print('\nFinding a potential energy function V while C is rolling with slip '
      'without friction.')
V = potential_energy(subs(Fr, {Px: 0, Py: 0}), q, u, kde_map)
if V is not None:
    print('Define a2, C as functions of t such that the respective '
          'contributing potential terms go to zero.')
    print('V = {0}'.format(V.subs(dict(zip(symbols('C α2'), [0, pi/2])))))
Exemple #4
0
pP1.v1pt_theory(pO, A, B)
pD_star.v2pt_theory(pP1, A, E)

## --- Expressions for generalized speeds u1, u2, u3 ---
kde = [u1 - dot(pP1.vel(A), E.x), u2 - dot(pP1.vel(A), E.y),
       u3 - dot(E.ang_vel_in(B), E.z)]
kde_map = solve(kde, [qd1, qd2, qd3])

## --- Velocity constraints ---
vc = [dot(pD_star.vel(B), E.y)]
vc_map = solve(subs(vc, kde_map), [u3])

## --- Define forces on each point in the system ---
K = k*E.x - k/L*dot(pP1.pos_from(pO), E.y)*E.y
gravity = lambda m: -m*g*A.y
forces = [(pP1, K), (pP1, gravity(m1)), (pD_star, gravity(m2))]

## --- Calculate generalized active forces ---
partials = partial_velocities(zip(*forces)[0], [u1, u2], A,
                              kde_map, vc_map)
Fr_tilde, _ = generalized_active_forces(partials, forces)
Fr_tilde = map(expand, map(trigsimp, Fr_tilde))

print('Finding a potential energy function V.')
V = potential_energy(Fr_tilde, [q1, q2, q3], [u1, u2], kde_map, vc_map)
if V is not None:
    print('V = {0}'.format(msprint(V)))
    print('Substituting αi = 0, C = 0...')
    zero_vars = dict(zip(symbols('C α1:4'), [0] * 4))
    print('V = {0}'.format(msprint(V.subs(zero_vars))))
Exemple #5
0
I = inertia(B, I1, I2, I3)  # central inertia dyadic of B

# forces, torques due to set of gravitational forces γ
C11, C12, C13, C21, C22, C23, C31, C32, C33 = [dot(x, y) for x in A for y in B]
f = 3 / M / q4**2 * ((I1 * (1 - 3 * C11**2) + I2 * (1 - 3 * C12**2) + I3 *
                      (1 - 3 * C13**2)) / 2 * A.x +
                     (I1 * C21 * C11 + I2 * C22 * C12 + I3 * C23 * C13) * A.y +
                     (I1 * C31 * C11 + I2 * C32 * C12 + I3 * C33 * C13) * A.z)
forces = [(pB_star, -G * m * M / q4**2 * (A.x + f))]
torques = [(B, cross(3 * G * m / q4**3 * A.x, dot(I, A.x)))]

partials = partial_velocities(
    zip(*forces + torques)[0], [u1, u2, u3, u4], A, kde_map)
Fr, _ = generalized_active_forces(partials, forces + torques)

V_gamma = potential_energy(Fr, [q1, q2, q3, q4], [u1, u2, u3, u4], kde_map)
print('V_γ = {0}'.format(msprint(V_gamma.subs(q4, R))))
print('Setting C = 0, α1, α2, α3 = 0, α4 = oo')
V_gamma = V_gamma.subs(dict(zip(symbols('C α1 α2 α3 α4'), [0] * 4 + [oo])))
print('V_γ= {0}'.format(msprint(V_gamma.subs(q4, R))))

V_gamma_expected = (-3 * G * m / 2 / R**3 *
                    ((I1 - I3) * sin(q2)**2 +
                     (I1 - I2) * cos(q2)**2 * sin(q3)**2) + G * m * M / R +
                    G * m / 2 / R**3 * (2 * I1 - I2 + I3))

print('V_γ - V_γ_expected = {0}'.format(
    msprint(trigsimp(expand(V_gamma.subs(q4, R)) - expand(V_gamma_expected)))))
assert trigsimp(expand(V_gamma.subs(q4, R) - V_gamma_expected)) == 0
Exemple #6
0
f = (
    3
    / M
    / q4 ** 2
    * (
        (I1 * (1 - 3 * C11 ** 2) + I2 * (1 - 3 * C12 ** 2) + I3 * (1 - 3 * C13 ** 2)) / 2 * A.x
        + (I1 * C21 * C11 + I2 * C22 * C12 + I3 * C23 * C13) * A.y
        + (I1 * C31 * C11 + I2 * C32 * C12 + I3 * C33 * C13) * A.z
    )
)
forces = [(pB_star, -G * m * M / q4 ** 2 * (A.x + f))]
torques = [(B, cross(3 * G * m / q4 ** 3 * A.x, dot(I, A.x)))]

partials = partial_velocities(zip(*forces + torques)[0], [u1, u2, u3, u4], A, kde_map)
Fr, _ = generalized_active_forces(partials, forces + torques)

V_gamma = potential_energy(Fr, [q1, q2, q3, q4], [u1, u2, u3, u4], kde_map)
print("V_γ = {0}".format(msprint(V_gamma.subs(q4, R))))
print("Setting C = 0, α1, α2, α3 = 0, α4 = oo")
V_gamma = V_gamma.subs(dict(zip(symbols("C α1 α2 α3 α4"), [0] * 4 + [oo])))
print("V_γ= {0}".format(msprint(V_gamma.subs(q4, R))))

V_gamma_expected = (
    -3 * G * m / 2 / R ** 3 * ((I1 - I3) * sin(q2) ** 2 + (I1 - I2) * cos(q2) ** 2 * sin(q3) ** 2)
    + G * m * M / R
    + G * m / 2 / R ** 3 * (2 * I1 - I2 + I3)
)

print("V_γ - V_γ_expected = {0}".format(msprint(trigsimp(expand(V_gamma.subs(q4, R)) - expand(V_gamma_expected)))))
assert trigsimp(expand(V_gamma.subs(q4, R) - V_gamma_expected)) == 0
Exemple #7
0
print(('\nVerify V_γ = {0} is a potential energy '.format(V_gamma) +
       'contribution of γ for C.'))
V_gamma_dot = -sum(
    fr * ur
    for fr, ur in zip(*generalized_active_forces(partials_tilde, forces[1:])))
if V_gamma_dot == V_gamma.diff(t).subs(kde_map):
    print('d/dt(V_γ) == -sum(Fr_γ * ur).')
else:
    print('d/dt(V_γ) != -sum(Fr_γ * ur).')
    print('d/dt(V_γ) = {0}'.format(msprint(V_gamma.diff(t))))
    print('-sum(Fr_γ * ur) = {0}'.format(msprint(V_gamma_dot)))

#print('\nFinding a potential energy function V while C is rolling '
#      'without slip.')
#V = potential_energy(Fr_tilde, q, u_indep, kde_map, vc_map)
#if V is not None:
#    print('V = {0}'.format(V))

print('\nFinding a potential energy function V while C is rolling with slip.')
V = potential_energy(Fr, q, u, kde_map)
if V is not None:
    print('V = {0}'.format(V))

print('\nFinding a potential energy function V while C is rolling with slip '
      'without friction.')
V = potential_energy(subs(Fr, {Px: 0, Py: 0}), q, u, kde_map)
if V is not None:
    print('Define a2, C as functions of t such that the respective '
          'contributing potential terms go to zero.')
    print('V = {0}'.format(V.subs(dict(zip(symbols('C α2'), [0, pi / 2])))))
Exemple #8
0
# kinematic differential equations
kde = [x - y for x, y in zip([u1, u2, u3], map(B.ang_vel_in(A).dot, B))]
kde_map = solve(kde, [q1d, q2d, q3d])

I = inertia(B, I1, I2, I3)  # central inertia dyadic of B

# forces, torques due to set of gravitational forces γ
forces = [(pB_star, -G * m * M / R**2 * A.x)]
torques = [(B, cross(3 * G * m / R**3 * A.x, dot(I, A.x)))]

partials = partial_velocities(
    zip(*forces + torques)[0], [u1, u2, u3], A, kde_map)
Fr, _ = generalized_active_forces(partials, forces + torques)

print('part a')
V_gamma = potential_energy(Fr, [q1, q2, q3], [u1, u2, u3], kde_map)
print('V_γ = {0}'.format(msprint(V_gamma)))
print('Setting C = 0, α1, α2, α3 = 0')
V_gamma = V_gamma.subs(dict(zip(symbols('C α1 α2 α3'), [0] * 4)))
print('V_γ= {0}'.format(msprint(V_gamma)))

V_gamma_expected = (-3 * G * m / 2 / R**3 *
                    ((I1 - I3) * sin(q2)**2 +
                     (I1 - I2) * cos(q2)**2 * sin(q3)**2))
assert expand(V_gamma) == expand(V_gamma_expected)

print('\npart b')
kde_b = [x - y for x, y in zip([u1, u2, u3], [q1d, q2d, q3d])]
kde_map_b = solve(kde_b, [q1d, q2d, q3d])
Fr_V_gamma = generalized_active_forces_V(V_gamma, [q1, q2, q3], [u1, u2, u3],
                                         kde_map_b)
Exemple #9
0
    p.set_vel(N, p.pos_from(pO).dt(N))

# kinematic differential equations
kde = [u1 - L*q1d, u2 - L*q2d, u3 - L*q3d]
kde_map = solve(kde, [q1d, q2d, q3d])

# gravity forces
forces = [(pP1, 6*m*g*N.x),
          (pP2, 5*m*g*N.x),
          (pP3, 6*m*g*N.x),
          (pP4, 5*m*g*N.x),
          (pP5, 6*m*g*N.x),
          (pP6, 5*m*g*N.x)]

# generalized active force contribution due to gravity
partials = partial_velocities(zip(*forces)[0], [u1, u2, u3], N, kde_map)
Fr, _ = generalized_active_forces(partials, forces)

print('Potential energy contribution of gravitational forces')
V = potential_energy(Fr, [q1, q2, q3], [u1, u2, u3], kde_map)
print('V = {0}'.format(msprint(V)))
print('Setting C = 0, αi = π/2')
V = V.subs(dict(zip(symbols('C α1:4'), [0] + [pi/2]*3)))
print('V = {0}\n'.format(msprint(V)))

print('Generalized active force contributions from Vγ.')
Fr_V = generalized_active_forces_V(V, [q1, q2, q3], [u1, u2, u3], kde_map)
print('Frγ = {0}'.format(msprint(Fr_V)))
print('Fr = {0}'.format(msprint(Fr)))

Exemple #10
0
pD_star.v2pt_theory(pP1, A, E)

## --- Expressions for generalized speeds u1, u2, u3 ---
kde = [
    u1 - dot(pP1.vel(A), E.x), u2 - dot(pP1.vel(A), E.y),
    u3 - dot(E.ang_vel_in(B), E.z)
]
kde_map = solve(kde, [qd1, qd2, qd3])

## --- Velocity constraints ---
vc = [dot(pD_star.vel(B), E.y)]
vc_map = solve(subs(vc, kde_map), [u3])

## --- Define forces on each point in the system ---
K = k * E.x - k / L * dot(pP1.pos_from(pO), E.y) * E.y
gravity = lambda m: -m * g * A.y
forces = [(pP1, K), (pP1, gravity(m1)), (pD_star, gravity(m2))]

## --- Calculate generalized active forces ---
partials = partial_velocities(zip(*forces)[0], [u1, u2], A, kde_map, vc_map)
Fr_tilde, _ = generalized_active_forces(partials, forces)
Fr_tilde = map(expand, map(trigsimp, Fr_tilde))

print('Finding a potential energy function V.')
V = potential_energy(Fr_tilde, [q1, q2, q3], [u1, u2], kde_map, vc_map)
if V is not None:
    print('V = {0}'.format(msprint(V)))
    print('Substituting αi = 0, C = 0...')
    zero_vars = dict(zip(symbols('C α1:4'), [0] * 4))
    print('V = {0}'.format(msprint(V.subs(zero_vars))))
Exemple #11
0
forces = [(pC1, -k * (x1.magnitude() - L_prime) * x1.normalize()),
          (pC2, -k * (x2.magnitude() - L_prime) * x2.normalize()),
          (pC3, -k * (x3.magnitude() - L_prime) * x3.normalize())]

partials = partial_velocities(zip(*forces)[0], u, X, kde_map)
Fr, _ = generalized_active_forces(partials, forces)
print('generalized active forces')
for i, fr in enumerate(Fr, 1):
    print('\nF{0} = {1}'.format(i, msprint(fr)))

# use a dummy symbol since series() does not work with dynamicsymbols
_q = Dummy('q')
series_exp = (
    lambda x, qi, n_: x.subs(qi, _q).series(_q, n=n_).removeO().subs(_q, qi))

# remove all terms order 3 or higher in qi
Fr_series = [reduce(lambda x, y: series_exp(x, y, 3), q, fr) for fr in Fr]
print('\nseries expansion of generalized active forces')
for i, fr in enumerate(Fr_series, 1):
    print('\nF{0} = {1}'.format(i, msprint(fr)))

V = potential_energy(Fr_series, q, u, kde_map)
print('\nV = {0}'.format(msprint(V)))
print('Setting C = 0, α1, α2, α3, α4, α5, α6 = 0')
V = V.subs(dict(zip(symbols('C α1 α2 α3 α4 α5 α6'), [0] * 7)))
print('V = {0}'.format(msprint(V)))

V_expected = k * a**2 / 2 * ((q1 - q5 - q6)**2 + (q2 - q6 - q4)**2 +
                             (q3 - q4 - q5)**2)
assert expand(V - V_expected) == 0
Exemple #12
0
# points, velocities
pO = Point('O') # Point O is at the center of the circular wire
pA = pO.locatenew('A', -r * A.z)
pB = pO.locatenew('B', -r * B.z)
pR_star = pO.locatenew('R*', 1/S(2) * (pA.pos_from(pO) + pB.pos_from(pO)))

pO.set_vel(N, 0)
pO.set_vel(C, 0)
for p in [pA, pB, pR_star]:
    p.set_vel(C, 0)
    p.v1pt_theory(pO, N, C)

# kinematic differential equations
kde = [u1 - q1d]
kde_map = solve(kde, [q1d])

# contact/distance forces
forces = [(pR_star, -m*g*N.z)]

partials = partial_velocities(zip(*forces)[0], [u1], N, kde_map)
Fr, _ = generalized_active_forces(partials, forces)

V = potential_energy(Fr, [q1], [u1], kde_map)
print('V = {0}'.format(msprint(V)))
print('Setting C = 0, α1 = π/2')
V = V.subs(dict(zip(symbols('C α1'), [0, pi/2])))
print('V = {0}'.format(msprint(V)))

assert V == -m*g*r*cos(theta)*cos(q1)
Exemple #13
0
# points, velocities
pO = Point('O') # Point O is at the center of the circular wire
pA = pO.locatenew('A', -r * A.z)
pB = pO.locatenew('B', -r * B.z)
pR_star = pO.locatenew('R*', 1/S(2) * (pA.pos_from(pO) + pB.pos_from(pO)))

pO.set_vel(N, 0)
pO.set_vel(C, 0)
for p in [pA, pB, pR_star]:
    p.set_vel(C, 0)
    p.v1pt_theory(pO, N, C)

# kinematic differential equations
kde = [u1 - q1d]
kde_map = solve(kde, [q1d])

# contact/distance forces
forces = [(pR_star, -m*g*N.z)]

partials = partial_velocities(zip(*forces)[0], [u1], N, kde_map)
Fr, _ = generalized_active_forces(partials, forces)

V = potential_energy(Fr, [q1], [u1], kde_map)
print('V = {0}'.format(msprint(V)))
print('Setting C = 0, α1 = π/2')
V = V.subs(dict(zip(symbols('C α1'), [0, pi/2])))
print('V = {0}'.format(msprint(V)))

assert V == -m*g*r*cos(theta)*cos(q1)
Exemple #14
0
k = 5 * m * g / L
r = (L_prime + L * sin(q)) * N.y + (L - L * cos(q)) * N.z
forces = [(pP, -m * g * N.z),
          (pP, -k * (r.magnitude() - L_prime) * r.normalize())]

partials = partial_velocities(zip(*forces)[0], [u], N, kde_map)
Fr, _ = generalized_active_forces(partials, forces)

# use a dummy symbol since series() does not work with dynamicsymbols
print('part a')
_q = Dummy('q')
terms = Fr[0].subs(q, _q).series(_q, n=4).removeO().subs(_q, q)
print('Using a series approximation of order 4:')
print('F1 ≈ {0}'.format(msprint(collect(terms, m * g * L))))

V = potential_energy([terms], [q], [u], kde_map)
print('V = {0}'.format(msprint(V)))
print('Setting C = 0, α1 = 0')
V = V.subs(dict(zip(symbols('C α1'), [0, 0])))
print('V = {0}'.format(msprint(collect(V, m * g * L))))

V_expected = m * g * L * (0 * q + 3 * q**2 + 0 * q**3 + -7 * q**4 / 8)
assert expand(V - V_expected) == 0

print('\npart b')
Fr_expected = m * g * L * (-6 * q + 0 * q**2 + 7 * q**3 / 2)

print('Fr using V')
Fr_V = generalized_active_forces_V(V, [q], [u], kde_map)
print('F1_V = {0}'.format(msprint(collect(Fr_V[0], m * g * L))))
assert expand(Fr_V[0] - Fr_expected) == 0
Exemple #15
0
for p in [pP1, pP2, pP3, pP4, pP5, pP6]:
    p.set_vel(N, p.pos_from(pO).dt(N))

# kinematic differential equations
kde = [u1 - L*q1d, u2 - L*q2d, u3 - L*q3d]
kde_map = solve(kde, [q1d, q2d, q3d])

# gravity forces
forces = [(pP1, 6*m*g*N.x),
          (pP2, 5*m*g*N.x),
          (pP3, 6*m*g*N.x),
          (pP4, 5*m*g*N.x),
          (pP5, 6*m*g*N.x),
          (pP6, 5*m*g*N.x)]

# generalized active force contribution due to gravity
partials = partial_velocities(zip(*forces)[0], [u1, u2, u3], N, kde_map)
Fr, _ = generalized_active_forces(partials, forces)

print('Potential energy contribution of gravitational forces')
V = potential_energy(Fr, [q1, q2, q3], [u1, u2, u3], kde_map)
print('V = {0}'.format(msprint(V)))
print('Setting C = 0, αi = π/2')
V = V.subs(dict(zip(symbols('C α1:4'), [0] + [pi/2]*3)))
print('V = {0}\n'.format(msprint(V)))

print('Generalized active force contributions from Vγ.')
Fr_V = generalized_active_forces_V(V, [q1, q2, q3], [u1, u2, u3], kde_map)
print('Frγ = {0}'.format(msprint(Fr_V)))
print('Fr = {0}'.format(msprint(Fr)))
Exemple #16
0
pP1 = pO.locatenew('P1', -q1 * N.x - b * N.z)
pP2 = pO.locatenew('P2', -q2 * N.x + b * N.z)
for p in [pB_star, pP1, pP2]:
    p.set_vel(N, p.pos_from(pO).diff(t, N))

# kinematic differential equations
kde = [u1 - q1d, u2 - q2d]
kde_map = solve(kde, [q1d, q2d])

# contact/distance forces
M = lambda qi, qj: 12 * E * I / (L**2) * (L / 3 * (qj - qi) / (2 * b) - qi / 2)
V = lambda qi, qj: 12 * E * I / (L**3) * (qi - L / 2 * (qj - qi) / (2 * b))

forces = [(pP1, V(q1, q2) * N.x), (pB_star, -m * g * N.x),
          (pP2, V(q2, q1) * N.x)]
# M2 torque is applied in the opposite direction
torques = [(B, (M(q1, q2) - M(q2, q1)) * N.y)]

partials = partial_velocities([pP1, pP2, pB_star, B], [u1, u2], N, kde_map)
Fr, _ = generalized_active_forces(partials, forces + torques)
V = simplify(potential_energy(Fr, [q1, q2], [u1, u2], kde_map))
print('V = {0}'.format(msprint(V)))
print('Setting C = 0, αi = 0')
V = V.subs(dict(zip(symbols('C α1:3'), [0] * 3)))
print('V = {0}\n'.format(msprint(V)))

assert (expand(V) == expand(6 * E * I / L**3 *
                            ((1 + L / 2 / b + L**2 / 6 / b**2) *
                             (q1**2 + q2**2) - q1 * q2 * L / b *
                             (1 + L / 3 / b)) - m * g / 2 * (q1 + q2)))
Exemple #17
0
pP2 = pO.locatenew('P2', -q2*N.x + b*N.z)
for p in [pB_star, pP1, pP2]:
    p.set_vel(N, p.pos_from(pO).diff(t, N))

# kinematic differential equations
kde = [u1 - q1d, u2 - q2d]
kde_map = solve(kde, [q1d, q2d])

# contact/distance forces
M = lambda qi, qj: 12*E*I/(L**2) * (L/3 * (qj - qi)/(2*b) - qi/2)
V = lambda qi, qj: 12*E*I/(L**3) * (qi - L/2 * (qj - qi)/(2*b))

forces = [(pP1, V(q1, q2)*N.x),
          (pB_star, -m*g*N.x),
          (pP2, V(q2, q1)*N.x)]
# M2 torque is applied in the opposite direction
torques = [(B, (M(q1, q2) - M(q2, q1))*N.y)]

partials = partial_velocities([pP1, pP2, pB_star, B], [u1, u2], N, kde_map)
Fr, _ = generalized_active_forces(partials, forces + torques)
V = simplify(potential_energy(Fr, [q1, q2], [u1, u2], kde_map))
print('V = {0}'.format(msprint(V)))
print('Setting C = 0, αi = 0')
V = V.subs(dict(zip(symbols('C α1:3'), [0] * 3)))
print('V = {0}\n'.format(msprint(V)))

assert (expand(V) ==
        expand(6*E*I/L**3 * ((1 + L/2/b + L**2/6/b**2)*(q1**2 + q2**2) -
                             q1*q2*L/b * (1 + L/3/b)) -
               m*g/2 * (q1 + q2)))
Exemple #18
0
# kinematic differential equations
kde = [x - y for x, y in zip([u1, u2, u3], map(B.ang_vel_in(A).dot, B))]
kde_map = solve(kde, [q1d, q2d, q3d])

I = inertia(B, I1, I2, I3) # central inertia dyadic of B

# forces, torques due to set of gravitational forces γ
forces = [(pB_star, -G * m * M / R**2 * A.x)]
torques = [(B, cross(3 * G * m / R**3 * A.x, dot(I, A.x)))]

partials = partial_velocities(zip(*forces + torques)[0], [u1, u2, u3],
                              A, kde_map)
Fr, _ = generalized_active_forces(partials, forces + torques)

print('part a')
V_gamma = potential_energy(Fr, [q1, q2, q3], [u1, u2, u3], kde_map)
print('V_γ = {0}'.format(msprint(V_gamma)))
print('Setting C = 0, α1, α2, α3 = 0')
V_gamma = V_gamma.subs(dict(zip(symbols('C α1 α2 α3'), [0] * 4)))
print('V_γ= {0}'.format(msprint(V_gamma)))

V_gamma_expected = (-3*G*m/2/R**3 * ((I1 - I3)*sin(q2)**2 +
                                     (I1 - I2)*cos(q2)**2*sin(q3)**2))
assert expand(V_gamma) == expand(V_gamma_expected)

print('\npart b')
kde_b = [x - y for x, y in zip([u1, u2, u3], [q1d, q2d, q3d])]
kde_map_b = solve(kde_b, [q1d, q2d, q3d])
Fr_V_gamma = generalized_active_forces_V(V_gamma, [q1, q2, q3],
                                         [u1, u2, u3], kde_map_b)
for i, fr in enumerate(Fr_V_gamma, 1):