Odd behavior in unit systems module

22 views
Skip to first unread message

cj.far...@gmail.com

unread,
Oct 26, 2020, 6:39:04 PM10/26/20
to sympy
I have noticed in the unit systems module I get odd behavior trying to convert to a unit that does not match the expression.  For example after importing 

>>> from sympy.physics.units import *

and executing 

>>> convert_to(5*V, ohm)
I get 
5*10**(1/3)*ohm**(8/9)

but other times it behaves as I would expect,  such as 

>>> convert_to(5*joule, m)
5*joule

Any ideas why this is occurring?  

Jonathan Gutow

unread,
Oct 26, 2020, 8:59:18 PM10/26/20
to sy...@googlegroups.com

This appears to be related to known issues. Please your add observations to the bug report so that those working on the units package may have as much information as possible.

See: https://github.com/sympy/sympy/issues/18368

A work around that involves more work on your part, but does not behave oddly is to define unit symbols as positive and real SymPy variables (e.g. `var('J kg m s', positive=True, real=True)`). They will behave as you expect. You can convert units by using syntax such as `.subs({J:kg*m**2/s**2})`, which would convert J to the SI base units.

Jonathan

On 10/26/20 5:39 PM, cj.far...@gmail.com wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/92a0cf64-b163-49a3-a76d-89ddc467ad44n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages