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


Python Quantity.convert_to方法代码示例

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


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

示例1: test_add_sub

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import convert_to [as 别名]
def test_add_sub():
    u = Quantity("u", length, 10)
    v = Quantity("v", length, 5)
    w = Quantity("w", time, 2)

    assert isinstance(u + v, Add)
    assert (u + v.convert_to(u)) == (1 + S.Half)*u
    # TODO: eventually add this:
    # assert (u + v).convert_to(u) == (1 + S.Half)*u
    assert isinstance(u - v, Add)
    assert (u - v.convert_to(u)) == S.Half*u
开发者ID:josephwillard,项目名称:sympy,代码行数:13,代码来源:test_quantities.py

示例2: test_convert_to

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import convert_to [as 别名]
def test_convert_to():
    q = Quantity("q1", length, 5000)
    assert q.convert_to(m) == 5000*m

    assert speed_of_light.convert_to(m / s) == 299792458 * m / s
    # TODO: eventually support this kind of conversion:
    # assert (2*speed_of_light).convert_to(m / s) == 2 * 299792458 * m / s
    assert day.convert_to(s) == 86400*s

    # Wrong dimension to convert:
    assert q.convert_to(s) == q
    assert speed_of_light.convert_to(m) == speed_of_light
开发者ID:josephwillard,项目名称:sympy,代码行数:14,代码来源:test_quantities.py

示例3: test_mul_div

# 需要导入模块: from sympy.physics.units.quantities import Quantity [as 别名]
# 或者: from sympy.physics.units.quantities.Quantity import convert_to [as 别名]
def test_mul_div():
    u = Quantity("u", length, 10)

    assert 1 / u == u**(-1)
    assert u / 1 == u

    v1 = u / Quantity("t", time, 2)
    v2 = Quantity("v", length / time, 5)

    # Pow only supports structural equality:
    assert v1 != v2
    assert v1 == v2.convert_to(v1)

    # TODO: decide whether to allow such expression in the future
    # (requires somehow manipulating the core).
    #assert u / Quantity(length, 2) == 5

    assert u * 1 == u

    ut1 = u * Quantity("t", time, 2)
    ut2 = Quantity("ut", length*time, 20)

    # Mul only supports structural equality:
    assert ut1 != ut2
    assert ut1 == ut2.convert_to(ut1)

    # Mul only supports structural equality:
    assert u * Quantity("lp1", length**-1, 2) != 20

    assert u**0 == 1
    assert u**1 == u
    # TODO: Pow only support structural equality:
    assert u ** 2 != Quantity("u2", length ** 2, 100)
    assert u ** -1 != Quantity("u3", length ** -1, 0.1)

    assert u ** 2 == Quantity("u2", length ** 2, 100).convert_to(u)
    assert u ** -1 == Quantity("u3", length ** -1, S.One/10).convert_to(u)
开发者ID:josephwillard,项目名称:sympy,代码行数:39,代码来源:test_quantities.py


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