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


Python Quantity.set_dimension方法代码示例

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


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

示例1: prefix_unit

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import set_dimension [as 别名]
def prefix_unit(unit, prefixes):
    """
    Return a list of all units formed by unit and the given prefixes.

    You can use the predefined PREFIXES or BIN_PREFIXES, but you can also
    pass as argument a subdict of them if you don't want all prefixed units.

        >>> from sympy.physics.units.prefixes import (PREFIXES,
        ...                                                 prefix_unit)
        >>> from sympy.physics.units.systems import MKS
        >>> from sympy.physics.units import m
        >>> pref = {"m": PREFIXES["m"], "c": PREFIXES["c"], "d": PREFIXES["d"]}
        >>> prefix_unit(m, pref)  #doctest: +SKIP
        [cm, dm, mm]
    """

    from sympy.physics.units.quantities import Quantity

    prefixed_units = []

    for prefix_abbr, prefix in prefixes.items():
        quantity = Quantity(
                "%s%s" % (prefix.name, unit.name),
                abbrev=("%s%s" % (prefix.abbrev, unit.abbrev))
           )
        quantity.set_dimension(unit.dimension)
        quantity.set_scale_factor(unit.scale_factor*prefix)
        prefixed_units.append(quantity)

    return prefixed_units
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:32,代码来源:prefixes.py

示例2: test_extend

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import set_dimension [as 别名]
def test_extend():
    ms = UnitSystem((m, s), (c,))
    Js = Quantity("Js")
    Js.set_dimension(action)
    Js.set_scale_factor(1)
    mks = ms.extend((kg,), (Js,))

    res = UnitSystem((m, s, kg), (c, Js))
    assert set(mks._base_units) == set(res._base_units)
    assert set(mks._units) == set(res._units)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:12,代码来源:test_unitsystem.py

示例3: test_print_unit_base

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import set_dimension [as 别名]
def test_print_unit_base():
    A = Quantity("A")
    A.set_dimension(current)
    A.set_scale_factor(S.One)

    Js = Quantity("Js")
    Js.set_dimension(action)
    Js.set_scale_factor(S.One)

    mksa = UnitSystem((m, kg, s, A), (Js,))
    with warns_deprecated_sympy():
        assert mksa.print_unit_base(Js) == m**2*kg*s**-1
开发者ID:asmeurer,项目名称:sympy,代码行数:14,代码来源:test_unitsystem.py

示例4: test_print_unit_base

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import set_dimension [as 别名]
def test_print_unit_base():
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=SymPyDeprecationWarning)

        A = Quantity("A")
        A.set_dimension(current)
        A.set_scale_factor(S.One)

        Js = Quantity("Js")
        Js.set_dimension(action)
        Js.set_scale_factor(S.One)

        mksa = UnitSystem((m, kg, s, A), (Js,))
        assert mksa.print_unit_base(Js) == m**2*kg*s**-1/1000
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:16,代码来源:test_unitsystem.py

示例5: test_definition

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import set_dimension [as 别名]
def test_definition():
    # want to test if the system can have several units of the same dimension
    dm = Quantity("dm")
    dm.set_dimension(length)

    dm.set_scale_factor(Rational(1, 10))

    base = (m, s)
    base_dim = (m.dimension, s.dimension)
    ms = UnitSystem(base, (c, dm), "MS", "MS system")

    assert set(ms._base_units) == set(base)
    assert set(ms._units) == set((m, s, c, dm))
    #assert ms._units == DimensionSystem._sort_dims(base + (velocity,))
    assert ms.name == "MS"
    assert ms.descr == "MS system"

    assert ms._system.base_dims == base_dim
    assert ms._system.derived_dims == (velocity,)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:21,代码来源:test_unitsystem.py

示例6: test_check_unit_consistency

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import set_dimension [as 别名]
def test_check_unit_consistency():
    u = Quantity("u")
    v = Quantity("v")
    w = Quantity("w")

    u.set_dimension(length)
    v.set_dimension(length)
    w.set_dimension(time)

    u.set_scale_factor(S(10))
    v.set_scale_factor(S(5))
    w.set_scale_factor(S(2))

    def check_unit_consistency(expr):
        Quantity._collect_factor_and_dimension(expr)

    raises(ValueError, lambda: check_unit_consistency(u + w))
    raises(ValueError, lambda: check_unit_consistency(u - w))
    raises(ValueError, lambda: check_unit_consistency(u + 1))
    raises(ValueError, lambda: check_unit_consistency(u - 1))
开发者ID:asmeurer,项目名称:sympy,代码行数:22,代码来源:test_quantities.py

示例7: import

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import set_dimension [as 别名]
from sympy.physics.units.prefixes import (
    centi, deci, kilo, micro, milli, nano, pico,
    kibi, mebi, gibi, tebi, pebi, exbi)

One = S.One

#### UNITS ####

# Dimensionless:

percent = percents = Quantity("percent")
percent.set_dimension(One)
percent.set_scale_factor(Rational(1, 100))

permille = Quantity("permille")
permille.set_dimension(One)
permille.set_scale_factor(Rational(1, 1000))


# Angular units (dimensionless)

rad = radian = radians = Quantity("radian")
radian.set_dimension(One)
radian.set_scale_factor(One)

deg = degree = degrees = Quantity("degree", abbrev="deg")
degree.set_dimension(One)
degree.set_scale_factor(pi/180)

sr = steradian = steradians = Quantity("steradian", abbrev="sr")
steradian.set_dimension(One)
开发者ID:asmeurer,项目名称:sympy,代码行数:33,代码来源:definitions.py


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