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


Python solveset.solveset函数代码示例

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


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

示例1: test_issue_9611

def test_issue_9611():
    x = Symbol("x")
    a = Symbol("a")
    y = Symbol("y")

    assert solveset(Eq(x - x + a, a), x, S.Reals) == S.Reals
    assert solveset(Eq(y - y + a, a), y) == S.Complexes
开发者ID:pabloferz,项目名称:sympy,代码行数:7,代码来源:test_solveset.py

示例2: test_issue_9522

def test_issue_9522():
    x = Symbol('x')
    expr1 = Eq(1/(x**2 - 4) + x, 1/(x**2 - 4) + 2)
    expr2 = Eq(1/x + x, 1/x)

    assert solveset(expr1, x, S.Reals) == EmptySet()
    assert solveset(expr2, x, S.Reals) == EmptySet()
开发者ID:nickle8424,项目名称:sympy,代码行数:7,代码来源:test_solveset.py

示例3: test_issue_9611

def test_issue_9611():
    x = Symbol("x", real=True)
    a = Symbol("a", real=True)
    y = Symbol("y")

    assert solveset(Eq(x - x + a, a), x) == S.Reals
    assert solveset(Eq(y - y + a, a), y) == S.Complex
开发者ID:vinothtronics,项目名称:sympy,代码行数:7,代码来源:test_solveset.py

示例4: test_issue_9522

def test_issue_9522():
    x = Symbol("x", real=True)
    expr1 = Eq(1 / (x ** 2 - 4) + x, 1 / (x ** 2 - 4) + 2)
    expr2 = Eq(1 / x + x, 1 / x)

    assert solveset(expr1, x) == EmptySet()
    assert solveset(expr2, x) == EmptySet()
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:7,代码来源:test_solveset.py

示例5: test_issue_9778

def test_issue_9778():
    assert solveset(x ** 3 + 1, x, S.Reals) == FiniteSet(-1)
    assert solveset(x ** (S(3) / 5) + 1, x, S.Reals) == S.EmptySet
    assert solveset(x ** 3 + y, x, S.Reals) == Intersection(
        Interval(-oo, oo),
        FiniteSet((-y) ** (S(1) / 3) * Piecewise((1, Ne(-im(y), 0)), ((-1) ** (S(2) / 3), -y < 0), (1, True))),
    )
开发者ID:pabloferz,项目名称:sympy,代码行数:7,代码来源:test_solveset.py

示例6: elm_domain

    def elm_domain(expr, intrvl):
        """ Finds the domain of an expression in any given interval """
        from sympy.solvers.solveset import solveset

        _start = intrvl.start
        _end = intrvl.end
        _singularities = solveset(expr.as_numer_denom()[1], symb,
                                  domain=S.Reals)

        if intrvl.right_open:
            if _end is S.Infinity:
                _domain1 = S.Reals
            else:
                _domain1 = solveset(expr < _end, symb, domain=S.Reals)
        else:
            _domain1 = solveset(expr <= _end, symb, domain=S.Reals)

        if intrvl.left_open:
            if _start is S.NegativeInfinity:
                _domain2 = S.Reals
            else:
                _domain2 = solveset(expr > _start, symb, domain=S.Reals)
        else:
            _domain2 = solveset(expr >= _start, symb, domain=S.Reals)

        # domain in the interval
        expr_with_sing = Intersection(_domain1, _domain2)
        expr_domain = Complement(expr_with_sing, _singularities)
        return expr_domain
开发者ID:tclose,项目名称:sympy,代码行数:29,代码来源:util.py

示例7: test_issue_9556

def test_issue_9556():
    x = Symbol('x')
    b = Symbol('b', positive=True)

    assert solveset(Abs(x) + 1, x, S.Reals) == EmptySet()
    assert solveset(Abs(x) + b, x, S.Reals) == EmptySet()
    assert solveset(Eq(b, -1), b, S.Reals) == EmptySet()
开发者ID:nickle8424,项目名称:sympy,代码行数:7,代码来源:test_solveset.py

示例8: contains

    def contains(self, other):
        """
        Is the other GeometryEntity contained within this Segment?

        Examples
        ========

        >>> from sympy import Point, Segment
        >>> p1, p2 = Point(0, 1), Point(3, 4)
        >>> s = Segment(p1, p2)
        >>> s2 = Segment(p2, p1)
        >>> s.contains(s2)
        True
        """
        if isinstance(other, Segment):
            return other.p1 in self and other.p2 in self
        elif isinstance(other, Point):
            if Point.is_collinear(self.p1, self.p2, other):
                t = Dummy('t')
                x, y = self.arbitrary_point(t).args
                if self.p1.x != self.p2.x:
                    ti = list(solveset(x - other.x, t))[0]
                else:
                    ti = list(solveset(y - other.y, t))[0]
                if ti.is_number:
                    return 0 <= ti <= 1
                return None

        return False
开发者ID:Kogorushi,项目名称:sympy,代码行数:29,代码来源:line.py

示例9: test_issue_9556

def test_issue_9556():
    x = Symbol("x", real=True)
    b = Symbol("b", positive=True)

    assert solveset(Abs(x) + 1, x) == EmptySet()
    assert solveset(Abs(x) + b, x) == EmptySet()
    assert solveset(Eq(b, -1), b) == EmptySet()
开发者ID:jonesnp,项目名称:sympy,代码行数:7,代码来源:test_solveset.py

示例10: continuous_domain

def continuous_domain(f, symbol, domain):
    """
    Returns the intervals in the given domain for which the function is continuous.
    This method is limited by the ability to determine the various
    singularities and discontinuities of the given function.

    Examples
    ========
    >>> from sympy import Symbol, S, tan, log, pi, sqrt
    >>> from sympy.sets import Interval
    >>> from sympy.calculus.util import continuous_domain
    >>> x = Symbol('x')
    >>> continuous_domain(1/x, x, S.Reals)
    (-oo, 0) U (0, oo)
    >>> continuous_domain(tan(x), x, Interval(0, pi))
    [0, pi/2) U (pi/2, pi]
    >>> continuous_domain(sqrt(x - 2), x, Interval(-5, 5))
    [2, 5]
    >>> continuous_domain(log(2*x - 1), x, S.Reals)
    (1/2, oo)

    """
    from sympy.solvers.inequalities import solve_univariate_inequality
    from sympy.solvers.solveset import solveset, _has_rational_power

    if domain.is_subset(S.Reals):
        constrained_interval = domain
        for atom in f.atoms(Pow):
            predicate, denom = _has_rational_power(atom, symbol)
            constraint = S.EmptySet
            if predicate and denom == 2:
                constraint = solve_univariate_inequality(atom.base >= 0,
                                                         symbol).as_set()
                constrained_interval = Intersection(constraint,
                                                    constrained_interval)

        for atom in f.atoms(log):
            constraint = solve_univariate_inequality(atom.args[0] > 0,
                                                     symbol).as_set()
            constrained_interval = Intersection(constraint,
                                                constrained_interval)

        domain = constrained_interval

    try:
        sings = S.EmptySet
        for atom in f.atoms(Pow):
            predicate, denom = _has_rational_power(atom, symbol)
            if predicate and denom == 2:
                sings = solveset(1/f, symbol, domain)
                break
        else:
            sings = Intersection(solveset(1/f, symbol), domain)

    except:
        raise NotImplementedError("Methods for determining the continuous domains"
                                  " of this function has not been developed.")

    return domain - sings
开发者ID:ataber,项目名称:sympy,代码行数:59,代码来源:util.py

示例11: _contains

 def _contains(self, other):
     from sympy.matrices import Matrix
     from sympy.solvers.solveset import solveset, linsolve
     from sympy.utilities.iterables import iterable, cartes
     L = self.lamda
     if self._is_multivariate():
         if not iterable(L.expr):
             if iterable(other):
                 return S.false
             return other.as_numer_denom() in self.func(
                 Lambda(L.variables, L.expr.as_numer_denom()), self.base_set)
         if len(L.expr) != len(self.lamda.variables):
             raise NotImplementedError(filldedent('''
 Dimensions of input and output of Lambda are different.'''))
         eqs = [expr - val for val, expr in zip(other, L.expr)]
         variables = L.variables
         free = set(variables)
         if all(i.is_number for i in list(Matrix(eqs).jacobian(variables))):
             solns = list(linsolve([e - val for e, val in
             zip(L.expr, other)], variables))
         else:
             syms = [e.free_symbols & free for e in eqs]
             solns = {}
             for i, (e, s, v) in enumerate(zip(eqs, syms, other)):
                 if not s:
                     if e != v:
                         return S.false
                     solns[vars[i]] = [v]
                     continue
                 elif len(s) == 1:
                     sy = s.pop()
                     sol = solveset(e, sy)
                     if sol is S.EmptySet:
                         return S.false
                     elif isinstance(sol, FiniteSet):
                         solns[sy] = list(sol)
                     else:
                         raise NotImplementedError
                 else:
                     raise NotImplementedError
             solns = cartes(*[solns[s] for s in variables])
     else:
         # assume scalar -> scalar mapping
         solnsSet = solveset(L.expr - other, L.variables[0])
         if solnsSet.is_FiniteSet:
             solns = list(solnsSet)
         else:
             raise NotImplementedError(filldedent('''
             Determining whether an ImageSet contains %s has not
             been implemented.''' % func_name(other)))
     for soln in solns:
         try:
             if soln in self.base_set:
                 return S.true
         except TypeError:
             return self.base_set.contains(soln.evalf())
     return S.false
开发者ID:Garsli,项目名称:sympy,代码行数:57,代码来源:fancysets.py

示例12: test_issue_11174

def test_issue_11174():
    r, t = symbols('r t')
    eq = z**2 + exp(2*x) - sin(y)
    soln = Intersection(S.Reals, FiniteSet(log(-z**2 + sin(y))/2))
    assert solveset(eq, x, S.Reals) == soln

    eq = sqrt(r)*Abs(tan(t))/sqrt(tan(t)**2 + 1) + x*tan(t)
    s = -sqrt(r)*Abs(tan(t))/(sqrt(tan(t)**2 + 1)*tan(t))
    soln = Intersection(S.Reals, FiniteSet(s))
    assert solveset(eq, x, S.Reals) == soln
开发者ID:Kogorushi,项目名称:sympy,代码行数:10,代码来源:test_solveset.py

示例13: test_invert_real

def test_invert_real():
    x = Symbol('x', real=True)
    x = Dummy(real=True)
    n = Symbol('n')
    d = Dummy()
    assert solveset(abs(x) - n, x) == solveset(abs(x) - d, x) == EmptySet()

    n = Symbol('n', real=True)
    assert invert_real(x + 3, y, x) == (x, FiniteSet(y - 3))
    assert invert_real(x*3, y, x) == (x, FiniteSet(y / 3))

    assert invert_real(exp(x), y, x) == (x, FiniteSet(log(y)))
    assert invert_real(exp(3*x), y, x) == (x, FiniteSet(log(y) / 3))
    assert invert_real(exp(x + 3), y, x) == (x, FiniteSet(log(y) - 3))

    assert invert_real(exp(x) + 3, y, x) == (x, FiniteSet(log(y - 3)))
    assert invert_real(exp(x)*3, y, x) == (x, FiniteSet(log(y / 3)))

    assert invert_real(log(x), y, x) == (x, FiniteSet(exp(y)))
    assert invert_real(log(3*x), y, x) == (x, FiniteSet(exp(y) / 3))
    assert invert_real(log(x + 3), y, x) == (x, FiniteSet(exp(y) - 3))

    assert invert_real(Abs(x), y, x) == (x, FiniteSet(-y, y))

    assert invert_real(2**x, y, x) == (x, FiniteSet(log(y)/log(2)))
    assert invert_real(2**exp(x), y, x) == (x, FiniteSet(log(log(y)/log(2))))

    assert invert_real(x**2, y, x) == (x, FiniteSet(sqrt(y), -sqrt(y)))
    assert invert_real(x**Rational(1, 2), y, x) == (x, FiniteSet(y**2))

    raises(ValueError, lambda: invert_real(x, x, x))
    raises(ValueError, lambda: invert_real(x**pi, y, x))
    raises(ValueError, lambda: invert_real(S.One, y, x))

    assert invert_real(x**31 + x, y, x) == (x**31 + x, FiniteSet(y))

    assert invert_real(Abs(x**31 + x + 1), y, x) == (x**31 + x,
                                                     FiniteSet(-y - 1, y - 1))

    assert invert_real(tan(x), y, x) == \
        (x, imageset(Lambda(n, n*pi + atan(y)), S.Integers))

    assert invert_real(tan(exp(x)), y, x) == \
        (x, imageset(Lambda(n, log(n*pi + atan(y))), S.Integers))

    assert invert_real(cot(x), y, x) == \
        (x, imageset(Lambda(n, n*pi + acot(y)), S.Integers))
    assert invert_real(cot(exp(x)), y, x) == \
        (x, imageset(Lambda(n, log(n*pi + acot(y))), S.Integers))

    assert invert_real(tan(tan(x)), y, x) == \
        (tan(x), imageset(Lambda(n, n*pi + atan(y)), S.Integers))

    x = Symbol('x', positive=True)
    assert invert_real(x**pi, y, x) == (x, FiniteSet(y**(1/pi)))
开发者ID:ChaliZhg,项目名称:sympy,代码行数:55,代码来源:test_solveset.py

示例14: 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)

    f = Piecewise(((x - 2) ** 2, x >= 0), (0, True))
    assert solveset(f, x, domain=S.Reals) == Union(FiniteSet(2), Interval(-oo, 0, True, True))

    assert solveset(Piecewise((x + 1, x > 0), (I, True)) - I, x) == Interval(-oo, 0)
开发者ID:pabloferz,项目名称:sympy,代码行数:12,代码来源:test_solveset.py

示例15: test_conditonset

def test_conditonset():
    assert solveset(Eq(sin(x)**2 + cos(x)**2, 1), x, domain=S.Reals) == \
        ConditionSet(x, True, S.Reals)

    assert solveset(Eq(x**2 + x*sin(x), 1), x, domain=S.Reals) == \
        ConditionSet(x, Eq(x*(x + sin(x)) - 1, 0), S.Reals)

    assert solveset(Eq(sin(Abs(x)), x), x, domain=S.Reals) == \
        ConditionSet(x, Eq(-x + sin(Abs(x)), 0), Interval(-oo, oo))

    assert solveset(Eq(-I*(exp(I*x) - exp(-I*x))/2, 1), x) == \
        imageset(Lambda(n, 2*n*pi + pi/2), S.Integers)

    assert solveset(x + sin(x) > 1, x, domain=S.Reals) == \
        ConditionSet(x, x + sin(x) > 1, S.Reals)
开发者ID:nickle8424,项目名称:sympy,代码行数:15,代码来源:test_solveset.py


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