• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sympy.Symbol类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.Symbol的典型用法代码示例。如果您正苦于以下问题:Python Symbol类的具体用法?Python Symbol怎么用?Python Symbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: get_dim

    def get_dim(self, dim):
        """
        Find a specific dimension which is part of the system.

        dim can be a string or a dimension object. If no dimension is found,
        then return None.
        """

        #TODO: if the argument is a list, return a list of all matching dims

        found_dim = None

        #TODO: use copy instead of direct assignment for found_dim?
        if isinstance(dim, string_types):
            dim = Symbol(dim)

        if dim.is_Symbol:
            for d in self._dims:
                if dim in (d.name, d.symbol):
                    found_dim = d
                    break
        elif isinstance(dim, Dimension):
            for i, idim in enumerate(self._dims):
                if dim.get_dimensional_dependencies() == idim.get_dimensional_dependencies():
                    return idim

        return found_dim
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:27,代码来源:dimensions.py


示例2: test_as_coeff_factors

def test_as_coeff_factors():
    x = Symbol("x")

    assert x.as_coeff_factors() == (0, (x,))
    assert (-1 + x).as_coeff_factors() == (-1, (x,))
    assert (2 + x).as_coeff_factors() == (2, (x,))
    assert (1 + x).as_coeff_factors() == (1, (x,))
开发者ID:unix0000,项目名称:sympy-polys,代码行数:7,代码来源:test_expr.py


示例3: test_diff

def test_diff():
    x = Symbol('x')
    assert Rational(1, 3).diff(x) is S.Zero
    assert I.diff(x) is S.Zero
    assert pi.diff(x) is S.Zero
    assert x.diff(x, 0) == x
    assert (x**2).diff(x, 2, x) == 0
    raises(ValueError, 'x.diff(1, x)')

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    p = Rational(5)
    e = a*b + b**p
    assert e.diff(a) == b
    assert e.diff(b) == a + 5*b**4
    assert e.diff(b).diff(a) == Rational(1)
    e = a*(b + c)
    assert e.diff(a) == b + c
    assert e.diff(b) == a
    assert e.diff(b).diff(a) == Rational(1)
    e = c**p
    assert e.diff(c, 6) == Rational(0)
    assert e.diff(c, 5) == Rational(120)
    e = c**Rational(2)
    assert e.diff(c) == 2*c
    e = a*b*c
    assert e.diff(c) == a*b
开发者ID:101man,项目名称:sympy,代码行数:28,代码来源:test_diff.py


示例4: test_K

def test_K():
    assert K(0) == pi / 2
    assert K(S(1) / 2) == 8 * pi ** (S(3) / 2) / gamma(-S(1) / 4) ** 2
    assert K(1) == zoo
    assert K(-1) == gamma(S(1) / 4) ** 2 / (4 * sqrt(2 * pi))
    assert K(oo) == 0
    assert K(-oo) == 0
    assert K(I * oo) == 0
    assert K(-I * oo) == 0
    assert K(zoo) == 0

    assert K(z).diff(z) == (E(z) - (1 - z) * K(z)) / (2 * z * (1 - z))
    assert td(K(z), z)

    zi = Symbol("z", real=False)
    assert K(zi).conjugate() == K(zi.conjugate())
    zr = Symbol("z", real=True, negative=True)
    assert K(zr).conjugate() == K(zr)

    assert K(z).rewrite(hyper) == (pi / 2) * hyper((S.Half, S.Half), (S.One,), z)
    assert tn(K(z), (pi / 2) * hyper((S.Half, S.Half), (S.One,), z))
    assert K(z).rewrite(meijerg) == meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z) / 2
    assert tn(K(z), meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z) / 2)

    assert K(z).series(
        z
    ) == pi / 2 + pi * z / 8 + 9 * pi * z ** 2 / 128 + 25 * pi * z ** 3 / 512 + 1225 * pi * z ** 4 / 32768 + 3969 * pi * z ** 5 / 131072 + O(
        z ** 6
    )
开发者ID:Carreau,项目名称:sympy,代码行数:29,代码来源:test_elliptic_integrals.py


示例5: test_Dummy_from_Symbol

def test_Dummy_from_Symbol():
    # should not get the full dictionary of assumptions
    n = Symbol('n', integer=True)
    d = n.as_dummy()
    s1 = "Dummy('n', dummy_index=%s, integer=True)" % str(d.dummy_index)
    s2 = "Dummy('n', integer=True, dummy_index=%s)" % str(d.dummy_index)
    assert srepr(d) in (s1, s2)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:7,代码来源:test_repr.py


示例6: test_E

def test_E():
    assert E(z, 0) == z
    assert E(0, m) == 0
    assert E(i*pi/2, m) == i*E(m)
    assert E(z, oo) == zoo
    assert E(z, -oo) == zoo
    assert E(0) == pi/2
    assert E(1) == 1
    assert E(oo) == I*oo
    assert E(-oo) == oo
    assert E(zoo) == zoo

    assert E(-z, m) == -E(z, m)

    assert E(z, m).diff(z) == sqrt(1 - m*sin(z)**2)
    assert E(z, m).diff(m) == (E(z, m) - F(z, m))/(2*m)
    assert E(z).diff(z) == (E(z) - K(z))/(2*z)
    r = randcplx()
    assert td(E(r, m), m)
    assert td(E(z, r), z)
    assert td(E(z), z)

    mi = Symbol('m', real=False)
    assert E(z, mi).conjugate() == E(z.conjugate(), mi.conjugate())
    mr = Symbol('m', real=True, negative=True)
    assert E(z, mr).conjugate() == E(z.conjugate(), mr)

    assert E(z).rewrite(hyper) == (pi/2)*hyper((-S.Half, S.Half), (S.One,), z)
    assert tn(E(z), (pi/2)*hyper((-S.Half, S.Half), (S.One,), z))
    assert E(z).rewrite(meijerg) == \
        -meijerg(((S.Half, S(3)/2), []), ((S.Zero,), (S.Zero,)), -z)/4
    assert tn(E(z), -meijerg(((S.Half, S(3)/2), []), ((S.Zero,), (S.Zero,)), -z)/4)
开发者ID:Maihj,项目名称:sympy,代码行数:32,代码来源:test_elliptic_integrals.py


示例7: __init__

    def __init__(self, data, step_size=1.0):
        """A continuous scalar data source from a discrete time series.

        Time series data points are linearly interpolated in order to generate
        values for points not present in the time series. The time series is
        wrapped in order to generate an infinite sequence.

        :param data: iterable of scalar values
        :param step_size: number of LB iterations corresponding to one unit in
            the time series (i.e. time distance between two neighboring points).
        """

        Symbol.__init__("unused")
        if type(data) is list or type(data) is tuple:
            data = np.float64(data)

        # Copy here is necessary so that the caller doesn't accidentally change
        # the underlying array later. Also, we need the array to be C-contiguous
        # (for __hash__ below), which might not be the case if it's a view.
        self._data = data.copy()
        self._step_size = step_size

        # To be set later by the geometry encoder class. This is necessary due
        # to how the printing system in Sympy works (see _ccode below).
        self._offset = None
开发者ID:marcinofulus,项目名称:sailfish,代码行数:25,代码来源:node_type.py


示例8: test_K

def test_K():
    assert K(0) == pi/2
    assert K(S(1)/2) == 8*pi**(S(3)/2)/gamma(-S(1)/4)**2
    assert K(1) == zoo
    assert K(-1) == gamma(S(1)/4)**2/(4*sqrt(2*pi))
    assert K(oo) == 0
    assert K(-oo) == 0
    assert K(I*oo) == 0
    assert K(-I*oo) == 0
    assert K(zoo) == 0

    assert K(z).diff(z) == (E(z) - (1 - z)*K(z))/(2*z*(1 - z))
    assert td(K(z), z)

    zi = Symbol('z', real=False)
    assert K(zi).conjugate() == K(zi.conjugate())
    zr = Symbol('z', real=True, negative=True)
    assert K(zr).conjugate() == K(zr)

    assert K(z).rewrite(hyper) == \
        (pi/2)*hyper((S.Half, S.Half), (S.One,), z)
    assert tn(K(z), (pi/2)*hyper((S.Half, S.Half), (S.One,), z))
    assert K(z).rewrite(meijerg) == \
        meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z)/2
    assert tn(K(z), meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z)/2)
开发者ID:Maihj,项目名称:sympy,代码行数:25,代码来源:test_elliptic_integrals.py


示例9: GeneralizedCoordinate

def GeneralizedCoordinate(s, constant=False):
    gc = Symbol(s)(Symbol("t"))
    gc.is_gc = True
    if constant == True:
        gc.fdiff = lambda argindex: 0
    gc.__repr__ = lambda self: PyDyStrPrinter().doprint(self)
    gc.__str__ = lambda self: PyDyStrPrinter().doprint(self)
    return gc
开发者ID:certik,项目名称:pydy,代码行数:8,代码来源:functions.py


示例10: test_atoms

def test_atoms():
   x = Symbol('x')
   y = Symbol('y')
   assert list((1+x).atoms()) == [1,x]
   assert list(x.atoms()) == [x]
   assert list((1+2*cos(x)).atoms(type=Symbol)) == [x]
   assert list((2*(x**(y**x))).atoms()) == [2,x,y]
   assert list(Rational(1,2).atoms()) == [Rational(1,2)]
   assert list(Rational(1,2).atoms(type=type(oo))) == []
开发者ID:certik,项目名称:sympy-oldcore,代码行数:9,代码来源:test_basic.py


示例11: test_as_dummy

def test_as_dummy():
    x = Symbol('x')
    x1 = x.as_dummy()
    assert x1 != x
    assert x1 != x.as_dummy()

    x = Symbol('x', commutative=False)
    x1 = x.as_dummy()
    assert x1 != x
    assert x1.is_commutative is False
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:10,代码来源:test_symbol.py


示例12: test_as_dummy_nondummy

def test_as_dummy_nondummy():
    x = Symbol('x')
    x1 = x.as_dummy()
    assert x1 != x
    assert x1 != x.as_dummy()
    # assert x == x1.as_nondummy()

    x = Symbol('x', commutative = False)
    x1 = x.as_dummy()
    assert x1 != x
    assert x1.is_commutative == False
开发者ID:Aang,项目名称:sympy,代码行数:11,代码来源:test_symbol.py


示例13: __init__

  def __init__(self, val):
    if not Expr.initialized:
      Expr.initialized = True
      Expr.init()

    if isinstance(val, int) or isinstance(val, long):
      self.expr = Integer(val)
    elif isinstance(val, basestring):
      self.expr = Symbol(val)
    elif isinstance(val, bool) or isinstance(val, BooleanAtom):
      self.expr = S.One if val else S.Zero
    else:
      assert isinstance(val, SymPyExpr) or isinstance(val, BooleanFunction) \
             or (val == S.Infinity) or (val == -S.Infinity)
      self.expr = val
开发者ID:AlisaMaas,项目名称:llvm-sage,代码行数:15,代码来源:expr.py


示例14: test_as_coeff_add

def test_as_coeff_add():
    x = Symbol("x")
    y = Symbol("y")

    assert S(2).as_coeff_add() == (2, ())
    assert S(3.0).as_coeff_add() == (0, (S(3.0),))
    assert S(-3.0).as_coeff_add() == (0, (S(-3.0),))
    assert x.as_coeff_add() == (0, (x,))
    assert (-1 + x).as_coeff_add() == (-1, (x,))
    assert (2 + x).as_coeff_add() == (2, (x,))
    assert (1 + x).as_coeff_add() == (1, (x,))
    assert (x + y).as_coeff_add(y) == (x, (y,))
    assert (3 * x).as_coeff_add(y) == (3 * x, ())
    # don't do expansion
    e = (x + y) ** 2
    assert e.as_coeff_add(y) == (0, (e,))
开发者ID:addisonc,项目名称:sympy,代码行数:16,代码来源:test_expr.py


示例15: __new__

 def __new__(cls, name, dim=None):
     obj = Symbol.__new__(cls, name)
     obj.dim = dim
     obj._fields = None
     obj._field_names = None
     obj._constant_fields = None
     return obj
开发者ID:IgnitionProject,项目名称:ignition,代码行数:7,代码来源:language.py


示例16: __new__

 def __new__(cls, i, label="sigma"):
     if not i in [1, 2, 3]:
         raise IndexError("Invalid Pauli index")
     obj = Symbol.__new__(cls, "%s%d" %(label,i), commutative=False, hermitian=True)
     obj.i = i
     obj.label = label
     return obj
开发者ID:asmeurer,项目名称:sympy,代码行数:7,代码来源:paulialgebra.py


示例17: test_dict_set

def test_dict_set():
    x = Symbol('x')
    a, b, c = map(Wild, 'abc')

    f = 3*cos(4*x)
    r = f.match(a*cos(b*x))
    assert r == {a: 3, b: 4}
    e = a/b*sin(b*x)
    assert e.subs(r) == r[a]/r[b]*sin(r[b]*x)
    assert e.subs(r) == 3*sin(4*x) / 4
    s = set(r.items())
    assert e.subs(s) == r[a]/r[b]*sin(r[b]*x)
    assert e.subs(s) == 3*sin(4*x) / 4

    assert e.subs(r) == r[a]/r[b]*sin(r[b]*x)
    assert e.subs(r) == 3*sin(4*x) / 4
    assert x.subs(Dict((x, 1))) == 1
开发者ID:malikdiarra,项目名称:sympy,代码行数:17,代码来源:test_subs.py


示例18: test_as_coeff_mul

def test_as_coeff_mul():
    x = Symbol("x")
    y = Symbol("y")

    assert S(2).as_coeff_mul() == (2, ())
    assert S(3.0).as_coeff_mul() == (1, (S(3.0),))
    assert S(-3.0).as_coeff_mul() == (-1, (S(3.0),))
    assert x.as_coeff_mul() == (1, (x,))
    assert (-x).as_coeff_mul() == (-1, (x,))
    assert (2 * x).as_coeff_mul() == (2, (x,))
    assert (x * y).as_coeff_mul(y) == (x, (y,))
    assert (3 + x).as_coeff_mul(y) == (3 + x, ())
    # don't do expansion
    e = exp(x + y)
    assert e.as_coeff_mul(y) == (1, (e,))
    e = 2 ** (x + y)
    assert e.as_coeff_mul(y) == (1, (e,))
开发者ID:addisonc,项目名称:sympy,代码行数:17,代码来源:test_expr.py


示例19: test_P

def test_P():
    assert P(0, z, m) == F(z, m)
    assert P(1, z, m) == F(z, m) + (sqrt(1 - m * sin(z) ** 2) * tan(z) - E(z, m)) / (1 - m)
    assert P(n, i * pi / 2, m) == i * P(n, m)
    assert P(n, z, 0) == atanh(sqrt(n - 1) * tan(z)) / sqrt(n - 1)
    assert P(n, z, n) == F(z, n) - P(1, z, n) + tan(z) / sqrt(1 - n * sin(z) ** 2)
    assert P(oo, z, m) == 0
    assert P(-oo, z, m) == 0
    assert P(n, z, oo) == 0
    assert P(n, z, -oo) == 0
    assert P(0, m) == K(m)
    assert P(1, m) == zoo
    assert P(n, 0) == pi / (2 * sqrt(1 - n))
    assert P(2, 1) == -oo
    assert P(-1, 1) == oo
    assert P(n, n) == E(n) / (1 - n)

    assert P(n, -z, m) == -P(n, z, m)

    ni, mi = Symbol("n", real=False), Symbol("m", real=False)
    assert P(ni, z, mi).conjugate() == P(ni.conjugate(), z.conjugate(), mi.conjugate())
    nr, mr = Symbol("n", real=True, negative=True), Symbol("m", real=True, negative=True)
    assert P(nr, z, mr).conjugate() == P(nr, z.conjugate(), mr)
    assert P(n, m).conjugate() == P(n.conjugate(), m.conjugate())

    assert P(n, z, m).diff(n) == (
        E(z, m)
        + (m - n) * F(z, m) / n
        + (n ** 2 - m) * P(n, z, m) / n
        - n * sqrt(1 - m * sin(z) ** 2) * sin(2 * z) / (2 * (1 - n * sin(z) ** 2))
    ) / (2 * (m - n) * (n - 1))
    assert P(n, z, m).diff(z) == 1 / (sqrt(1 - m * sin(z) ** 2) * (1 - n * sin(z) ** 2))
    assert P(n, z, m).diff(m) == (
        E(z, m) / (m - 1) + P(n, z, m) - m * sin(2 * z) / (2 * (m - 1) * sqrt(1 - m * sin(z) ** 2))
    ) / (2 * (n - m))
    assert P(n, m).diff(n) == (E(m) + (m - n) * K(m) / n + (n ** 2 - m) * P(n, m) / n) / (2 * (m - n) * (n - 1))
    assert P(n, m).diff(m) == (E(m) / (m - 1) + P(n, m)) / (2 * (n - m))
    rx, ry = randcplx(), randcplx()
    assert td(P(n, rx, ry), n)
    assert td(P(rx, z, ry), z)
    assert td(P(rx, ry, m), m)

    assert P(n, z, m).series(z) == z + z ** 3 * (m / 6 + n / 3) + z ** 5 * (
        3 * m ** 2 / 40 + m * n / 10 - m / 30 + n ** 2 / 5 - n / 15
    ) + O(z ** 6)
开发者ID:Carreau,项目名称:sympy,代码行数:45,代码来源:test_elliptic_integrals.py


示例20: test_F

def test_F():
    assert F(z, 0) == z
    assert F(0, m) == 0
    assert F(pi*i/2, m) == i*K(m)
    assert F(z, oo) == 0
    assert F(z, -oo) == 0

    assert F(-z, m) == -F(z, m)

    assert F(z, m).diff(z) == 1/sqrt(1 - m*sin(z)**2)
    assert F(z, m).diff(m) == E(z, m)/(2*m*(1 - m)) - F(z, m)/(2*m) - \
        sin(2*z)/(4*(1 - m)*sqrt(1 - m*sin(z)**2))
    r = randcplx()
    assert td(F(z, r), z)
    assert td(F(r, m), m)

    mi = Symbol('m', real=False)
    assert F(z, mi).conjugate() == F(z.conjugate(), mi.conjugate())
    mr = Symbol('m', real=True, negative=True)
    assert F(z, mr).conjugate() == F(z.conjugate(), mr)
开发者ID:Maihj,项目名称:sympy,代码行数:20,代码来源:test_elliptic_integrals.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sympy.ZZ类代码示例发布时间:2022-05-27
下一篇:
Python sympy.Sum类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap