You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromsympy.physics.unitsimportconvert_tofromsympy.physics.units.systems.cgsimportcgs_gaussfromsympy.physics.units.definitions.unit_definitionsimportcoulomb, erg, volt, joule, meter, newton, statvoltfromsympy.physics.units.definitions.unit_definitionsimportstatcoulombasesuprint(convert_to(volt, joule/coulomb))
# it gives joule/coulombprint(convert_to(volt/meter, newton/coulomb))
# it gives newton/coulombprint(convert_to(statvolt, erg/esu))
# but it gives statvolt
The text was updated successfully, but these errors were encountered:
def _get_conversion_matrix_for_expr(expr, target_units, unit_system):
from sympy.matrices.dense import Matrix
dimension_system = unit_system.get_dimension_system()
expr_dim = Dimension(unit_system.get_dimensional_expr(expr))
dim_dependencies = dimension_system.get_dimensional_dependencies(expr_dim, mark_dimensionless=True)
target_dims = [Dimension(unit_system.get_dimensional_expr(x)) for x in target_units]
canon_dim_units = [i for x in target_dims for i in dimension_system.get_dimensional_dependencies(x, mark_dimensionless=True)]
canon_expr_units = set(dim_dependencies)
if not canon_expr_units.issubset(set(canon_dim_units)):
return None
seen = set()
canon_dim_units = [i for i in canon_dim_units if not (i in seen or seen.add(i))]
camat = Matrix([[dimension_system.get_dimensional_dependencies(i, mark_dimensionless=True).get(j, 0) for i in target_dims] for j in canon_dim_units])
exprmat = Matrix([dim_dependencies.get(k, 0) for k in canon_dim_units])
try:
res_exponents = camat.solve(exprmat)
except NonInvertibleMatrixError:
return None
return res_exponents
if not canon_expr_units.issubset(set(canon_dim_units)):
return None
The problem occurs here . Why are we doing this ?
Removing this keeps rest of the results same but gives
The text was updated successfully, but these errors were encountered: