Physical quantities

Physical quantities.

class sympy.physics.units.quantities.Quantity(name, dimension, scale_factor=1, abbrev=None, **assumptions)[source]

Physical quantity.

property abbrev

Symbol representing the unit name.

Prepend the abbreviation with the prefix symbol if it is defines.

convert_to(other)[source]

Convert the quantity to another quantity of same dimensions.

Examples

>>> from sympy.physics.units import speed_of_light, meter, second
>>> speed_of_light
speed_of_light
>>> speed_of_light.convert_to(meter/second)
299792458*meter/second
>>> from sympy.physics.units import liter
>>> liter.convert_to(meter**3)
meter**3/1000
property free_symbols

Return from the atoms of self those which are free symbols.

For most expressions, all symbols are free symbols. For some classes this is not true. e.g. Integrals use Symbols for the dummy variables which are bound variables, so Integral has a method to return all symbols except those. Derivative keeps track of symbols with respect to which it will perform a derivative; those are bound variables, too, so it has its own free_symbols method.

Any other method that uses bound variables should implement a free_symbols method.

property scale_factor

Overall magnitude of the quantity as compared to the canonical units.

Conversion between quantities

Several methods to simplify expressions involving unit objects.

sympy.physics.units.util.convert_to(expr, target_units)[source]

Convert expr to the same expression with all of its units and quantities represented as factors of target_units, whenever the dimension is compatible.

target_units may be a single unit/quantity, or a collection of units/quantities.

Examples

>>> from sympy.physics.units import speed_of_light, meter, gram, second, day
>>> from sympy.physics.units import mile, newton, kilogram, atomic_mass_constant
>>> from sympy.physics.units import kilometer, centimeter
>>> from sympy.physics.units import convert_to
>>> convert_to(mile, kilometer)
25146*kilometer/15625
>>> convert_to(mile, kilometer).n()
1.609344*kilometer
>>> convert_to(speed_of_light, meter/second)
299792458*meter/second
>>> convert_to(day, second)
86400*second
>>> 3*newton
3*newton
>>> convert_to(3*newton, kilogram*meter/second**2)
3*kilogram*meter/second**2
>>> convert_to(atomic_mass_constant, gram)
1.66053904e-24*gram

Conversion to multiple units:

>>> convert_to(speed_of_light, [meter, second])
299792458*meter/second
>>> convert_to(3*newton, [centimeter, gram, second])
300000*centimeter*gram/second**2

Conversion to Planck units:

>>> from sympy.physics.units import gravitational_constant, hbar
>>> convert_to(atomic_mass_constant, [gravitational_constant, speed_of_light, hbar]).n()
7.62950196312651e-20*gravitational_constant**(-0.5)*hbar**0.5*speed_of_light**0.5