本文整理汇总了Python中sympy.physics.units.quantities.Quantity._collect_factor_and_dimension方法的典型用法代码示例。如果您正苦于以下问题:Python Quantity._collect_factor_and_dimension方法的具体用法?Python Quantity._collect_factor_and_dimension怎么用?Python Quantity._collect_factor_and_dimension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.physics.units.quantities.Quantity
的用法示例。
在下文中一共展示了Quantity._collect_factor_and_dimension方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_factor_and_dimension
# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import _collect_factor_and_dimension [as 别名]
def test_factor_and_dimension():
assert (3000, Dimension(1)) == Quantity._collect_factor_and_dimension(3000)
assert (1001, length) == Quantity._collect_factor_and_dimension(meter + km)
assert (2, length/time) == Quantity._collect_factor_and_dimension(
meter/second + 36*km/(10*hour))
x, y = symbols('x y')
assert (x + y/100, length) == Quantity._collect_factor_and_dimension(
x*m + y*centimeter)
cH = Quantity('cH', amount_of_substance/volume)
pH = -log(cH)
assert (1, volume/amount_of_substance) == Quantity._collect_factor_and_dimension(
exp(pH))
v_w1 = Quantity('v_w1', length/time, S(3)/2*meter/second)
v_w2 = Quantity('v_w2', length/time, 2*meter/second)
expr = Abs(v_w1/2 - v_w2)
assert (S(5)/4, length/time) == \
Quantity._collect_factor_and_dimension(expr)
expr = S(5)/2*second/meter*v_w1 - 3000
assert (-(2996 + S(1)/4), Dimension(1)) == \
Quantity._collect_factor_and_dimension(expr)
expr = v_w1**(v_w2/v_w1)
assert ((S(3)/2)**(S(4)/3), (length/time)**(S(4)/3)) == \
Quantity._collect_factor_and_dimension(expr)
示例2: test_dimensional_expr_of_derivative
# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import _collect_factor_and_dimension [as 别名]
def test_dimensional_expr_of_derivative():
l = Quantity('l', length, 36 * km)
t = Quantity('t', time, hour)
t1 = Quantity('t1', time, second)
x = Symbol('x')
y = Symbol('y')
f = Function('f')
dfdx = f(x, y).diff(x, y)
dl_dt = dfdx.subs({f(x, y): l, x: t, y: t1})
assert Quantity.get_dimensional_expr(dl_dt) ==\
Quantity.get_dimensional_expr(l / t / t1) ==\
Symbol("length")/Symbol("time")**2
assert Quantity._collect_factor_and_dimension(dl_dt) ==\
Quantity._collect_factor_and_dimension(l / t / t1) ==\
(10, length/time**2)
示例3: dim_simplify
# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import _collect_factor_and_dimension [as 别名]
def dim_simplify(expr):
"""
NOTE: this function could be deprecated in the future.
Simplify expression by recursively evaluating the dimension arguments.
This function proceeds to a very rough dimensional analysis. It tries to
simplify expression with dimensions, and it deletes all what multiplies a
dimension without being a dimension. This is necessary to avoid strange
behavior when Add(L, L) be transformed into Mul(2, L).
"""
_, expr = Quantity._collect_factor_and_dimension(expr)
return expr
示例4: dim_simplify
# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import _collect_factor_and_dimension [as 别名]
def dim_simplify(expr):
"""
NOTE: this function could be deprecated in the future.
Simplify expression by recursively evaluating the dimension arguments.
This function proceeds to a very rough dimensional analysis. It tries to
simplify expression with dimensions, and it deletes all what multiplies a
dimension without being a dimension. This is necessary to avoid strange
behavior when Add(L, L) be transformed into Mul(2, L).
"""
SymPyDeprecationWarning(
deprecated_since_version="1.2",
feature="dimensional simplification function",
issue=13336,
useinstead="don't use",
).warn()
_, expr = Quantity._collect_factor_and_dimension(expr)
return expr
示例5: test_factor_and_dimension_with_Abs
# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import _collect_factor_and_dimension [as 别名]
def test_factor_and_dimension_with_Abs():
v_w1 = Quantity('v_w1', length/time, S(3)/2*meter/second)
expr = v_w1 - Abs(v_w1)
assert (0, lenth/time) == Quantity._collect_factor_and_dimension(expr)