ruletest5.py 1.9 KB

123456789101112131415161718192021222324252627282930313233
  1. import sympy.physics.mechanics as _me
  2. import sympy as _sm
  3. import math as m
  4. import numpy as _np
  5. x, y = _me.dynamicsymbols('x y')
  6. x_d, y_d = _me.dynamicsymbols('x_ y_', 1)
  7. e1 = (x+y)**2+(x-y)**3
  8. e2 = (x-y)**2
  9. e3 = x**2+y**2+2*x*y
  10. m1 = _sm.Matrix([e1,e2]).reshape(2, 1)
  11. m2 = _sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)
  12. m3 = m1+_sm.Matrix([x,y]).reshape(2, 1)
  13. am = _sm.Matrix([i.expand() for i in m1]).reshape((m1).shape[0], (m1).shape[1])
  14. cm = _sm.Matrix([i.expand() for i in _sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)]).reshape((_sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)).shape[0], (_sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)).shape[1])
  15. em = _sm.Matrix([i.expand() for i in m1+_sm.Matrix([x,y]).reshape(2, 1)]).reshape((m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[0], (m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[1])
  16. f = (e1).expand()
  17. g = (e2).expand()
  18. a = _sm.factor((e3), x)
  19. bm = _sm.Matrix([_sm.factor(i, x) for i in m1]).reshape((m1).shape[0], (m1).shape[1])
  20. cm = _sm.Matrix([_sm.factor(i, x) for i in m1+_sm.Matrix([x,y]).reshape(2, 1)]).reshape((m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[0], (m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[1])
  21. a = (e3).diff(x)
  22. b = (e3).diff(y)
  23. cm = _sm.Matrix([i.diff(x) for i in m2]).reshape((m2).shape[0], (m2).shape[1])
  24. dm = _sm.Matrix([i.diff(x) for i in m1+_sm.Matrix([x,y]).reshape(2, 1)]).reshape((m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[0], (m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[1])
  25. frame_a = _me.ReferenceFrame('a')
  26. frame_b = _me.ReferenceFrame('b')
  27. frame_b.orient(frame_a, 'DCM', _sm.Matrix([1,0,0,1,0,0,1,0,0]).reshape(3, 3))
  28. v1 = x*frame_a.x+y*frame_a.y+x*y*frame_a.z
  29. e = (v1).diff(x, frame_b)
  30. fm = _sm.Matrix([i.diff(_sm.Symbol('t')) for i in m1]).reshape((m1).shape[0], (m1).shape[1])
  31. gm = _sm.Matrix([i.diff(_sm.Symbol('t')) for i in _sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)]).reshape((_sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)).shape[0], (_sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)).shape[1])
  32. h = (v1).dt(frame_b)