ruletest6.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import sympy.physics.mechanics as _me
  2. import sympy as _sm
  3. import math as m
  4. import numpy as _np
  5. q1, q2 = _me.dynamicsymbols('q1 q2')
  6. x, y, z = _me.dynamicsymbols('x y z')
  7. e = q1+q2
  8. a = (e).subs({q1:x**2+y**2, q2:x-y})
  9. e2 = _sm.cos(x)
  10. e3 = _sm.cos(x*y)
  11. a = (e2).series(x, 0, 2).removeO()
  12. b = (e3).series(x, 0, 2).removeO().series(y, 0, 2).removeO()
  13. e = ((x+y)**2).expand()
  14. a = (e).subs({q1:x**2+y**2,q2:x-y}).subs({x:1,y:z})
  15. bm = _sm.Matrix([i.subs({x:1,y:z}) for i in _sm.Matrix([e,2*e]).reshape(2, 1)]).reshape((_sm.Matrix([e,2*e]).reshape(2, 1)).shape[0], (_sm.Matrix([e,2*e]).reshape(2, 1)).shape[1])
  16. e = q1+q2
  17. a = (e).subs({q1:x**2+y**2,q2:x-y}).subs({x:2,y:z**2})
  18. j, k, l = _sm.symbols('j k l', real=True)
  19. p1 = _sm.Poly(_sm.Matrix([j,k,l]).reshape(1, 3), x)
  20. p2 = _sm.Poly(j*x+k, x)
  21. root1 = [i.evalf() for i in _sm.solve(p1, x)]
  22. root2 = [i.evalf() for i in _sm.solve(_sm.Poly(_sm.Matrix([1,2,3]).reshape(3, 1), x),x)]
  23. m = _sm.Matrix([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]).reshape(4, 4)
  24. am = (m).T+m
  25. bm = _sm.Matrix([i.evalf() for i in (m).eigenvals().keys()])
  26. c1 = _sm.diag(1,1,1,1)
  27. c2 = _sm.Matrix([2 if i==j else 0 for i in range(3) for j in range(4)]).reshape(3, 4)
  28. dm = (m+c1)**(-1)
  29. e = (m+c1).det()+(_sm.Matrix([1,0,0,1]).reshape(2, 2)).trace()
  30. f = (m)[1,2]
  31. a = (m).cols
  32. bm = (m).col(0)
  33. cm = _sm.Matrix([(m).T.row(0),(m).T.row(1),(m).T.row(2),(m).T.row(3),(m).T.row(2)])
  34. dm = (m).row(0)
  35. em = _sm.Matrix([(m).row(0),(m).row(1),(m).row(2),(m).row(3),(m).row(2)])