Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 599
pixatlazaki Avatar asked Aug 17 '14 03:08

pixatlazaki


1 Answers

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.

like image 74
asmeurer Avatar answered Nov 08 '22 10:11

asmeurer