图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

  1. from sympy.core.backend import symbols
  2. from sympy.physics.mechanics import dynamicsymbols
  3. from sympy.physics.mechanics import ReferenceFrame, Point, Particle
  4. from sympy.physics.mechanics import LagrangesMethod, Lagrangian
  5. ### This test asserts that a system with more than one external forces
  6. ### is acurately formed with Lagrange method (see issue #8626)
  7. def test_lagrange_2forces():
  8. ### Equations for two damped springs in serie with two forces
  9. ### generalized coordinates
  10. q1, q2 = dynamicsymbols('q1, q2')
  11. ### generalized speeds
  12. q1d, q2d = dynamicsymbols('q1, q2', 1)
  13. ### Mass, spring strength, friction coefficient
  14. m, k, nu = symbols('m, k, nu')
  15. N = ReferenceFrame('N')
  16. O = Point('O')
  17. ### Two points
  18. P1 = O.locatenew('P1', q1 * N.x)
  19. P1.set_vel(N, q1d * N.x)
  20. P2 = O.locatenew('P1', q2 * N.x)
  21. P2.set_vel(N, q2d * N.x)
  22. pP1 = Particle('pP1', P1, m)
  23. pP1.potential_energy = k * q1**2 / 2
  24. pP2 = Particle('pP2', P2, m)
  25. pP2.potential_energy = k * (q1 - q2)**2 / 2
  26. #### Friction forces
  27. forcelist = [(P1, - nu * q1d * N.x),
  28. (P2, - nu * q2d * N.x)]
  29. lag = Lagrangian(N, pP1, pP2)
  30. l_method = LagrangesMethod(lag, (q1, q2), forcelist=forcelist, frame=N)
  31. l_method.form_lagranges_equations()
  32. eq1 = l_method.eom[0]
  33. assert eq1.diff(q1d) == nu
  34. eq2 = l_method.eom[1]
  35. assert eq2.diff(q2d) == nu