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

Python solveset.solveset_real函数代码示例

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

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



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

示例1: test_garbage_input

def test_garbage_input():
    raises(ValueError, lambda: solveset_real([x], x))
    raises(ValueError, lambda: solveset_real(x, pi))
    raises(ValueError, lambda: solveset_real(x, x ** 2))

    raises(ValueError, lambda: solveset_complex([x], x))
    raises(ValueError, lambda: solveset_complex(x, pi))
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:7,代码来源:test_solveset.py


示例2: test_solve_rational

def test_solve_rational():
    assert solveset_real(1/x + 1, x) == FiniteSet(-S.One)
    assert solveset_real(1/exp(x) - 1, x) == FiniteSet(0)
    assert solveset_real(x*(1 - 5/x), x) == FiniteSet(5)
    assert solveset_real(2*x/(x + 2) - 1, x) == FiniteSet(2)
    assert solveset_real((x**2/(7 - x)).diff(x), x) == \
        FiniteSet(S(0), S(14))
开发者ID:nickle8424,项目名称:sympy,代码行数:7,代码来源:test_solveset.py


示例3: test_solve_trig

def test_solve_trig():
    from sympy.abc import n

    assert solveset_real(sin(x), x) == Union(
        imageset(Lambda(n, 2 * pi * n), S.Integers), imageset(Lambda(n, 2 * pi * n + pi), S.Integers)
    )

    assert solveset_real(sin(x) - 1, x) == imageset(Lambda(n, 2 * pi * n + pi / 2), S.Integers)

    assert solveset_real(cos(x), x) == Union(
        imageset(Lambda(n, 2 * pi * n - pi / 2), S.Integers), imageset(Lambda(n, 2 * pi * n + pi / 2), S.Integers)
    )

    assert solveset_real(sin(x) + cos(x), x) == Union(
        imageset(Lambda(n, 2 * n * pi - pi / 4), S.Integers), imageset(Lambda(n, 2 * n * pi + 3 * pi / 4), S.Integers)
    )

    assert solveset_real(sin(x) ** 2 + cos(x) ** 2, x) == S.EmptySet

    assert solveset_complex(cos(x) - S.Half, x) == Union(
        imageset(Lambda(n, 2 * n * pi + pi / 3), S.Integers), imageset(Lambda(n, 2 * n * pi - pi / 3), S.Integers)
    )

    y, a = symbols("y,a")
    assert solveset(sin(y + a) - sin(y), a, domain=S.Reals) == Union(
        imageset(Lambda(n, 2 * n * pi), S.Integers),
        imageset(Lambda(n, -I * (I * (2 * n * pi + arg(-exp(-2 * I * y))) + 2 * im(y))), S.Integers),
    )
开发者ID:pabloferz,项目名称:sympy,代码行数:28,代码来源:test_solveset.py


示例4: test_uselogcombine_1

def test_uselogcombine_1():
    assert solveset_real(log(x - 3) + log(x + 3), x) == \
        FiniteSet(sqrt(10))
    assert solveset_real(log(x + 1) - log(2*x - 1), x) == FiniteSet(2)
    assert solveset_real(log(x + 3) + log(1 + 3/x) - 3) == FiniteSet(
        -3 + sqrt(-12 + exp(3))*exp(S(3)/2)/2 + exp(3)/2,
        -sqrt(-12 + exp(3))*exp(S(3)/2)/2 - 3 + exp(3)/2)
开发者ID:nickle8424,项目名称:sympy,代码行数:7,代码来源:test_solveset.py


示例5: test_solve_abs

def test_solve_abs():
    assert solveset_real(Abs(x) - 2, x) == FiniteSet(-2, 2)
    assert solveset_real(Abs(x + 3) - 2*Abs(x - 3), x) == \
        FiniteSet(1, 9)
    assert solveset_real(2*Abs(x) - Abs(x - 1), x) == \
        FiniteSet(-1, Rational(1, 3))

    assert solveset_real(Abs(x - 7) - 8, x) == FiniteSet(-S(1), S(15))
开发者ID:ChaliZhg,项目名称:sympy,代码行数:8,代码来源:test_solveset.py


示例6: test_solve_trig_simplified

def test_solve_trig_simplified():
    from sympy.abc import n

    assert solveset_real(sin(x), x) == imageset(Lambda(n, n * pi), S.Integers)

    assert solveset_real(cos(x), x) == imageset(Lambda(n, n * pi + pi / 2), S.Integers)

    assert solveset_real(cos(x) + sin(x), x) == imageset(Lambda(n, n * pi - pi / 4), S.Integers)
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:8,代码来源:test_solveset.py


示例7: test_errorinverses

def test_errorinverses():
    assert solveset_real(erf(x) - S.One/2, x) == \
        FiniteSet(erfinv(S.One/2))
    assert solveset_real(erfinv(x) - 2, x) == \
        FiniteSet(erf(2))
    assert solveset_real(erfc(x) - S.One, x) == \
        FiniteSet(erfcinv(S.One))
    assert solveset_real(erfcinv(x) - 2, x) == FiniteSet(erfc(2))
开发者ID:nickle8424,项目名称:sympy,代码行数:8,代码来源:test_solveset.py


示例8: test_piecewise

def test_piecewise():
    eq = Piecewise((x - 2, Gt(x, 2)), (2 - x, True)) - 3
    f = Piecewise(((x - 2) ** 2, x >= 0), (0, True))
    assert set(solveset_real(eq, x)) == set(FiniteSet(-1, 5))
    absxm3 = Piecewise((x - 3, S(0) <= x - 3), (3 - x, S(0) > x - 3))
    y = Symbol("y", positive=True)
    assert solveset_real(absxm3 - y, x) == FiniteSet(-y + 3, y + 3)
    assert solveset(f, x, domain=S.Reals) == Union(FiniteSet(2), Interval(-oo, 0, True, True))
开发者ID:JackWangCUMT,项目名称:sympy,代码行数:8,代码来源:test_solveset.py


示例9: test_piecewise

def test_piecewise():
    eq = Piecewise((x - 2, Gt(x, 2)), (2 - x, True)) - 3
    assert set(solveset_real(eq, x)) == set(FiniteSet(-1, 5))
    absxm3 = Piecewise(
        (x - 3, S(0) <= x - 3),
        (3 - x, S(0) > x - 3)
    )
    y = Symbol('y', positive=True)
    assert solveset_real(absxm3 - y, x) == FiniteSet(-y + 3, y + 3)
开发者ID:ChaliZhg,项目名称:sympy,代码行数:9,代码来源:test_solveset.py


示例10: test_solve_polynomial_cv_1a

def test_solve_polynomial_cv_1a():
    """
    Test for solving on equations that can be converted to
    a polynomial equation using the change of variable y -> x**Rational(p, q)
    """
    assert solveset_real(sqrt(x) - 1, x) == FiniteSet(1)
    assert solveset_real(sqrt(x) - 2, x) == FiniteSet(4)
    assert solveset_real(x ** Rational(1, 4) - 2, x) == FiniteSet(16)
    assert solveset_real(x ** Rational(1, 3) - 3, x) == FiniteSet(27)
    assert solveset_real(x * (x ** (S(1) / 3) - 3), x) == FiniteSet(S(0), S(27))
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:10,代码来源:test_solveset.py


示例11: test_solve_sqrt_3

def test_solve_sqrt_3():
    R = Symbol("R")
    eq = sqrt(2) * R * sqrt(1 / (R + 1)) + (R + 1) * (sqrt(2) * sqrt(1 / (R + 1)) - 1)
    sol = solveset_complex(eq, R)

    assert sol == FiniteSet(
        *[
            S(5) / 3 + 4 * sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) / 3,
            -sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) / 3
            + 40 * re(1 / ((-S(1) / 2 - sqrt(3) * I / 2) * (S(251) / 27 + sqrt(111) * I / 9) ** (S(1) / 3))) / 9
            + sqrt(30) * sin(atan(3 * sqrt(111) / 251) / 3) / 3
            + S(5) / 3
            + I
            * (
                -sqrt(30) * cos(atan(3 * sqrt(111) / 251) / 3) / 3
                - sqrt(10) * sin(atan(3 * sqrt(111) / 251) / 3) / 3
                + 40 * im(1 / ((-S(1) / 2 - sqrt(3) * I / 2) * (S(251) / 27 + sqrt(111) * I / 9) ** (S(1) / 3))) / 9
            ),
        ]
    )

    # the number of real roots will depend on the value of m: for m=1 there are 4
    # and for m=-1 there are none.
    eq = -sqrt((m - q) ** 2 + (-m / (2 * q) + S(1) / 2) ** 2) + sqrt(
        (-m ** 2 / 2 - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) / 4 - S(1) / 4) ** 2
        + (m ** 2 / 2 - m - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) / 4 - S(1) / 4) ** 2
    )
    raises(NotImplementedError, lambda: solveset_real(eq, q))
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:28,代码来源:test_solveset.py


示例12: test_solve_polynomial

def test_solve_polynomial():
    assert solveset_real(3 * x - 2, x) == FiniteSet(Rational(2, 3))

    assert solveset_real(x ** 2 - 1, x) == FiniteSet(-S(1), S(1))
    assert solveset_real(x - y ** 3, x) == FiniteSet(y ** 3)

    a11, a12, a21, a22, b1, b2 = symbols("a11, a12, a21, a22, b1, b2")

    assert solveset_real(x ** 3 - 15 * x - 4, x) == FiniteSet(-2 + 3 ** Rational(1, 2), S(4), -2 - 3 ** Rational(1, 2))

    assert solveset_real(sqrt(x) - 1, x) == FiniteSet(1)
    assert solveset_real(sqrt(x) - 2, x) == FiniteSet(4)
    assert solveset_real(x ** Rational(1, 4) - 2, x) == FiniteSet(16)
    assert solveset_real(x ** Rational(1, 3) - 3, x) == FiniteSet(27)
    assert len(solveset_real(x ** 5 + x ** 3 + 1, x)) == 1
    assert len(solveset_real(-2 * x ** 3 + 4 * x ** 2 - 2 * x + 6, x)) > 0
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:16,代码来源:test_solveset.py


示例13: test_rewrite_trigh

def test_rewrite_trigh():
    # if this import passes then the test below should also pass
    from sympy import sech
    assert solveset_real(sinh(x) + sech(x), x) == FiniteSet(
        2*atanh(-S.Half + sqrt(5)/2 - sqrt(-2*sqrt(5) + 2)/2),
        2*atanh(-S.Half + sqrt(5)/2 + sqrt(-2*sqrt(5) + 2)/2),
        2*atanh(-sqrt(5)/2 - S.Half + sqrt(2 + 2*sqrt(5))/2),
        2*atanh(-sqrt(2 + 2*sqrt(5))/2 - sqrt(5)/2 - S.Half))
开发者ID:nickle8424,项目名称:sympy,代码行数:8,代码来源:test_solveset.py


示例14: test_solve_abs

def test_solve_abs():
    assert solveset_real(Abs(x) - 2, x) == FiniteSet(-2, 2)
    assert solveset_real(Abs(x + 3) - 2 * Abs(x - 3), x) == FiniteSet(1, 9)
    assert solveset_real(2 * Abs(x) - Abs(x - 1), x) == FiniteSet(-1, Rational(1, 3))

    assert solveset_real(Abs(x - 7) - 8, x) == FiniteSet(-S(1), S(15))

    # issue 9565. Note: solveset_real does not solve this as it is
    # solveset's job to handle Relationals
    assert solveset(Abs((x - 1) / (x - 5)) <= S(1) / 3, domain=S.Reals) == Interval(-1, 2)

    # issue #10069
    eq = abs(1 / (x - 1)) - 1 > 0
    u = Union(Interval.open(0, 1), Interval.open(1, 2))
    assert solveset_real(eq, x) == u
    assert solveset(eq, x, domain=S.Reals) == u

    raises(ValueError, lambda: solveset(abs(x) - 1, x))
开发者ID:pabloferz,项目名称:sympy,代码行数:18,代码来源:test_solveset.py


示例15: test_solve_trig

def test_solve_trig():
    from sympy.abc import n
    assert solveset_real(sin(x), x) == \
        Union(imageset(Lambda(n, 2*pi*n), S.Integers),
              imageset(Lambda(n, 2*pi*n + pi), S.Integers))

    assert solveset_real(sin(x) - 1, x) == \
        imageset(Lambda(n, 2*pi*n + pi/2), S.Integers)

    assert solveset_real(cos(x), x) == \
        Union(imageset(Lambda(n, 2*pi*n - pi/2), S.Integers),
              imageset(Lambda(n, 2*pi*n + pi/2), S.Integers))

    assert solveset_real(sin(x) + cos(x), x) == \
        Union(imageset(Lambda(n, 2*n*pi - pi/4), S.Integers),
              imageset(Lambda(n, 2*n*pi + 3*pi/4), S.Integers))

    assert solveset_real(sin(x)**2 + cos(x)**2, x) == S.EmptySet
开发者ID:nickle8424,项目名称:sympy,代码行数:18,代码来源:test_solveset.py


示例16: codomain_interval

    def codomain_interval(f, set_val, *sym):
        symb = sym[0]
        df1 = diff(f, symb)
        df2 = diff(df1, symb)
        der_zero = solveset_real(df1, symb)
        der_zero_in_dom = closure_handle(set_val, der_zero)

        local_maxima = set()
        local_minima = set()
        start_val = limit(f, symb, set_val.start)
        end_val = limit(f, symb, set_val.end, '-')

        if start_val is S.Infinity or end_val is S.Infinity:
            local_maxima = set([(oo, True)])
        elif start_val is S.NegativeInfinity or end_val is S.NegativeInfinity:
            local_minima = set([(-oo, True)])

        if local_maxima == set():
            if start_val > end_val:
                local_maxima = set([(start_val, set_val.left_open)])
            elif start_val < end_val:
                local_maxima = set([(end_val, set_val.right_open)])
            else:
                local_maxima = set([(start_val, set_val.left_open and set_val.right_open)])

        if local_minima == set():
            if start_val < end_val:
                local_minima = set([(start_val, set_val.left_open)])
            elif start_val > end_val:
                local_minima = set([(end_val, set_val.right_open)])
            else:
                local_minima = set([(start_val, set_val.left_open and set_val.right_open)])

        for i in der_zero_in_dom:
            exist = not i in set_val
            if df2.subs({symb: i}) < 0:
                local_maxima.add((f.subs({symb: i}), exist))
            elif df2.subs({symb: i}) > 0:
                local_minima.add((f.subs({symb: i}), exist))

        maximum = (-oo, True)
        minimum = (oo, True)

        for i in local_maxima:
            if i[0] > maximum[0]:
                maximum = i
            elif i[0] == maximum[0]:
                maximum = (maximum[0], i[1] and maximum[1])

        for i in local_minima:
            if i[0] < minimum[0]:
                minimum = i
            elif i[0] == minimum[0]:
                minimum = (minimum[0], i[1] and minimum[1])

        return Union(Interval(minimum[0], maximum[0], minimum[1], maximum[1]))
开发者ID:kumarkrishna,项目名称:sympy,代码行数:56,代码来源:codomain.py


示例17: test_solve_abs

def test_solve_abs():
    assert solveset_real(Abs(x) - 2, x) == FiniteSet(-2, 2)
    assert solveset_real(Abs(x + 3) - 2*Abs(x - 3), x) == \
        FiniteSet(1, 9)
    assert solveset_real(2*Abs(x) - Abs(x - 1), x) == \
        FiniteSet(-1, Rational(1, 3))

    assert solveset_real(Abs(x - 7) - 8, x) == FiniteSet(-S(1), S(15))

    # issue 9565. Note: solveset_real does not solve this as it is
    # solveset's job to handle Relationals
    assert solveset(Abs((x - 1)/(x - 5)) <= S(1)/3, domain=S.Reals
        ) == Interval(-1, 2)

    # issue #10069
    assert solveset_real(abs(1/(x - 1)) - 1 > 0, x) == \
        ConditionSet(x, Eq((1 - Abs(x - 1))/Abs(x - 1) > 0, 0),
            S.Reals)
    assert solveset(abs(1/(x - 1)) - 1 > 0, x, domain=S.Reals
        ) == Union(Interval.open(0, 1), Interval.open(1, 2))
开发者ID:nickle8424,项目名称:sympy,代码行数:20,代码来源:test_solveset.py


示例18: test_no_sol

def test_no_sol():
    assert solveset_real(4, x) == EmptySet()
    assert solveset_real(exp(x), x) == EmptySet()
    assert solveset_real(x ** 2 + 1, x) == EmptySet()
    assert solveset_real(-3 * a / sqrt(x), x) == EmptySet()
    assert solveset_real(1 / x, x) == EmptySet()
    assert solveset_real(-(1 + x) / (2 + x) ** 2 + 1 / (2 + x), x) == EmptySet()
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:7,代码来源:test_solveset.py


示例19: test_solveset_sqrt_1

def test_solveset_sqrt_1():
    assert solveset_real(sqrt(5 * x + 6) - 2 - x, x) == FiniteSet(-S(1), S(2))
    assert solveset_real(sqrt(x - 1) - x + 7, x) == FiniteSet(10)
    assert solveset_real(sqrt(x - 2) - 5, x) == FiniteSet(27)
    assert solveset_real(sqrt(x) - 2 - 5, x) == FiniteSet(49)
    assert solveset_real(sqrt(x ** 3), x) == FiniteSet(0)
    assert solveset_real(sqrt(x - 1), x) == FiniteSet(1)
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:7,代码来源:test_solveset.py


示例20: _intersect

    def _intersect(self, other):
        from sympy.solvers.diophantine import diophantine
        if self.base_set is S.Integers:
            g = None
            if isinstance(other, ImageSet) and other.base_set is S.Integers:
                g = other.lamda.expr
                m = other.lamda.variables[0]
            elif other is S.Integers:
                m = g = Dummy('x')
            if g is not None:
                f = self.lamda.expr
                n = self.lamda.variables[0]
                # Diophantine sorts the solutions according to the alphabetic
                # order of the variable names, since the result should not depend
                # on the variable name, they are replaced by the dummy variables
                # below
                a, b = Dummy('a'), Dummy('b')
                f, g = f.subs(n, a), g.subs(m, b)
                solns_set = diophantine(f - g)
                if solns_set == set():
                    return EmptySet()
                solns = list(diophantine(f - g))

                if len(solns) != 1:
                    return

                # since 'a' < 'b', select soln for n
                nsol = solns[0][0]
                t = nsol.free_symbols.pop()
                return imageset(Lambda(n, f.subs(a, nsol.subs(t, n))), S.Integers)

        if other == S.Reals:
            from sympy.solvers.solveset import solveset_real
            from sympy.core.function import expand_complex
            if len(self.lamda.variables) > 1:
                return None

            f = self.lamda.expr
            n = self.lamda.variables[0]

            n_ = Dummy(n.name, real=True)
            f_ = f.subs(n, n_)

            re, im = f_.as_real_imag()
            im = expand_complex(im)

            return imageset(Lambda(n_, re),
                            self.base_set.intersect(
                                solveset_real(im, n_)))
开发者ID:AStorus,项目名称:sympy,代码行数:49,代码来源:fancysets.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python stats.cdf函数代码示例发布时间:2022-05-27
下一篇:
Python solveset.solveset_complex函数代码示例发布时间: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