当前位置: 首页>>代码示例>>Python>>正文


Python Quantity.get_dimensional_expr方法代码示例

本文整理汇总了Python中sympy.physics.units.quantities.Quantity.get_dimensional_expr方法的典型用法代码示例。如果您正苦于以下问题:Python Quantity.get_dimensional_expr方法的具体用法?Python Quantity.get_dimensional_expr怎么用?Python Quantity.get_dimensional_expr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.physics.units.quantities.Quantity的用法示例。


在下文中一共展示了Quantity.get_dimensional_expr方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dimensional_expr_of_derivative

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [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)
开发者ID:josephwillard,项目名称:sympy,代码行数:17,代码来源:test_quantities.py

示例2: __add__

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [as 别名]
 def __add__(self, other):
     from sympy.physics.units.quantities import Quantity
     other = sympify(other)
     if isinstance(other, Basic):
         if other.has(Quantity):
             other = Dimension(Quantity.get_dimensional_expr(other))
         if isinstance(other, Dimension) and self == other:
             return self
         return super(Dimension, self).__add__(other)
     return self
开发者ID:bjodah,项目名称:sympy,代码行数:12,代码来源:dimensions.py

示例3: _get_conversion_matrix_for_expr

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [as 别名]
def _get_conversion_matrix_for_expr(expr, target_units):
    from sympy import Matrix

    expr_dim = Dimension(Quantity.get_dimensional_expr(expr))
    dim_dependencies = expr_dim.get_dimensional_dependencies(mark_dimensionless=True)
    target_dims = [Dimension(Quantity.get_dimensional_expr(x)) for x in target_units]
    canon_dim_units = {i for x in target_dims for i in x.get_dimensional_dependencies(mark_dimensionless=True)}
    canon_expr_units = {i for i in dim_dependencies}

    if not canon_expr_units.issubset(canon_dim_units):
        return None

    canon_dim_units = sorted(canon_dim_units)

    camat = Matrix([[i.get_dimensional_dependencies(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])

    res_exponents = camat.solve_least_squares(exprmat, method=None)
    return res_exponents
开发者ID:sixpearls,项目名称:sympy,代码行数:21,代码来源:util.py

示例4: __mul__

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [as 别名]
 def __mul__(self, other):
     from sympy.physics.units.quantities import Quantity
     if isinstance(other, Basic):
         if other.has(Quantity):
             other = Dimension(Quantity.get_dimensional_expr(other))
         if isinstance(other, Dimension):
             return Dimension(self.name*other.name)
         if not other.free_symbols: # other.is_number cannot be used
             return self
         return super(Dimension, self).__mul__(other)
     return self
开发者ID:bjodah,项目名称:sympy,代码行数:13,代码来源:dimensions.py

示例5: test_quantity_postprocessing

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [as 别名]
def test_quantity_postprocessing():
    q1 = Quantity('q1', length*pressure**2*temperature/time)
    q2 = Quantity('q2', energy*pressure*temperature/(length**2*time))
    assert q1 + q2
    q = q1 + q2
    Dq = Dimension(Quantity.get_dimensional_expr(q))
    assert dimsys_default.get_dimensional_dependencies(Dq) == {
        'length': -1,
        'mass': 2,
        'temperature': 1,
        'time': -5,
    }
开发者ID:baoqchau,项目名称:sympy,代码行数:14,代码来源:test_quantities.py

示例6: test_quantity_abs

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [as 别名]
def test_quantity_abs():
    v_w1 = Quantity('v_w1', length/time, meter/second)
    v_w2 = Quantity('v_w2', length/time, meter/second)
    v_w3 = Quantity('v_w3', length/time, meter/second)
    expr = v_w3 - Abs(v_w1 - v_w2)

    Dq = Dimension(Quantity.get_dimensional_expr(expr))
    assert dimsys_default.get_dimensional_dependencies(Dq) == {
        'length': 1,
        'time': -1,
    }
    assert meter == sqrt(meter**2)
开发者ID:baoqchau,项目名称:sympy,代码行数:14,代码来源:test_quantities.py

示例7: check_dimensions

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [as 别名]
def check_dimensions(expr):
    """Return expr if there are not unitless values added to
    dimensional quantities, else raise a ValueError."""
    from sympy.solvers.solveset import _term_factors
    # the case of adding a number to a dimensional quantity
    # is ignored for the sake of SymPy core routines, so this
    # function will raise an error now if such an addend is
    # found.
    # Also, when doing substitutions, multiplicative constants
    # might be introduced, so remove those now
    adds = expr.atoms(Add)
    DIM_OF = dimsys_default.get_dimensional_dependencies
    for a in adds:
        deset = set()
        for ai in a.args:
            if ai.is_number:
                deset.add(())
                continue
            dims = []
            skip = False
            for i in Mul.make_args(ai):
                if i.has(Quantity):
                    i = Dimension(Quantity.get_dimensional_expr(i))
                if i.has(Dimension):
                    dims.extend(DIM_OF(i).items())
                elif i.free_symbols:
                    skip = True
                    break
            if not skip:
                deset.add(tuple(sorted(dims)))
                if len(deset) > 1:
                    raise ValueError(
                        "addends have incompatible dimensions")

    # clear multiplicative constants on Dimensions which may be
    # left after substitution
    reps = {}
    for m in expr.atoms(Mul):
        if any(isinstance(i, Dimension) for i in m.args):
            reps[m] = m.func(*[
                i for i in m.args if not i.is_number])

    return expr.xreplace(reps)
开发者ID:bjodah,项目名称:sympy,代码行数:45,代码来源:util.py

示例8: test_get_dimensional_expr_with_function_1

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [as 别名]
def test_get_dimensional_expr_with_function_1():
    v_w1 = Quantity('v_w1', length / time, meter / second)
    v_w2 = Quantity('v_w2', length / time, meter / second)
    assert Quantity.get_dimensional_expr(sin(v_w1/v_w2)) == 1
开发者ID:baoqchau,项目名称:sympy,代码行数:6,代码来源:test_quantities.py

示例9: test_get_dimensional_expr_with_function

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [as 别名]
def test_get_dimensional_expr_with_function():
    v_w1 = Quantity('v_w1', length / time, meter / second)
    assert Quantity.get_dimensional_expr(sin(v_w1)) == \
        sin(Quantity.get_dimensional_expr(v_w1))
开发者ID:baoqchau,项目名称:sympy,代码行数:6,代码来源:test_quantities.py

示例10: Quantity

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import get_dimensional_expr [as 别名]
mebibyte = mebibytes = Quantity("mebibyte")
mebibyte.set_dimension(information)
mebibyte.set_scale_factor(mebi*byte)

gibibyte = gibibytes = Quantity("gibibyte")
gibibyte.set_dimension(information)
gibibyte.set_scale_factor(gibi*byte)

tebibyte = tebibytes = Quantity("tebibyte")
tebibyte.set_dimension(information)
tebibyte.set_scale_factor(tebi*byte)

pebibyte = pebibytes = Quantity("pebibyte")
pebibyte.set_dimension(information)
pebibyte.set_scale_factor(pebi*byte)

exbibyte = exbibytes = Quantity("exbibyte")
exbibyte.set_dimension(information)
exbibyte.set_scale_factor(exbi*byte)


# check that scale factors are the right SI dimensions:
for _scale_factor, _dimension in zip(
        Quantity.SI_quantity_scale_factors.values(),
        Quantity.SI_quantity_dimension_map.values()):
    dimex = Quantity.get_dimensional_expr(_scale_factor)
    if dimex != 1:
        if not dimsys_default.equivalent_dims(_dimension, Dimension(dimex)):
            raise ValueError("quantity value and dimension mismatch")
del _scale_factor, _dimension
开发者ID:asmeurer,项目名称:sympy,代码行数:32,代码来源:definitions.py


注:本文中的sympy.physics.units.quantities.Quantity.get_dimensional_expr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。