Is it possible to implement Newton's Dot Notation (or Lagrange's Prime Notation) in sympy?

烈酒焚心 提交于 2020-12-05 08:26:49

问题


Leibniz's notation can just be a bit cluttering, especially in physics problems where time is the only variable that functions are being differentiated with respect to. Additionally, is it possible to not display the (t) for a function like x(t) with sympy still understanding that x is a function of t and treating it as such?


回答1:


You can use the mechanics module, which was designed around Newtonian physics. In particular, dynamicssymbols will give you a symbol which implicitly depends on t.

In [10]: x, y = dynamicsymbols('x y')

In [11]: x
Out[11]: x(t)

By default, these will still print with the (t), but if you enable the mechanics printers, they will not.

In [1]: from sympy.physics.mechanics import dynamicsymbols, init_vprinting

In [2]: init_vprinting
Out[2]: <function sympy.physics.vector.printing.init_vprinting>

In [3]: init_vprinting()

In [4]: x
Out[4]: x

In [5]: t = sympy.Symbol('t')

In [6]: y.diff(t)
Out[6]: ẏ

Use init_vprinting instead of init_printing in whatever interactive environment you develop in, such as the IPython notebook (there are also functions like mpprint if you want to print things from a scrpt).

If you want to know more about the SymPy mechanics module, read the documentation, and also take a look at the tutorial from the 2014 SciPy conference.



来源:https://stackoverflow.com/questions/25346132/is-it-possible-to-implement-newtons-dot-notation-or-lagranges-prime-notation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!