本文整理汇总了Python中sympy.solvers.solveset.solveset函数的典型用法代码示例。如果您正苦于以下问题:Python solveset函数的具体用法?Python solveset怎么用?Python solveset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了solveset函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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
示例17: _eval_subs
def _eval_subs(self, old, new):
if old in self.variables:
newexpr = self.expr.subs(old, new)
i = self.variables.index(old)
newvars = list(self.variables)
newpt = list(self.point)
if new.is_Symbol:
newvars[i] = new
else:
syms = new.free_symbols
if len(syms) == 1 or old in syms:
if old in syms:
var = self.variables[i]
else:
var = syms.pop()
# First, try to substitute self.point in the "new"
# expr to see if this is a fixed point.
# E.g. O(y).subs(y, sin(x))
point = new.subs(var, self.point[i])
if point != self.point[i]:
from sympy.solvers.solveset import solveset
d = Dummy()
sol = solveset(old - new.subs(var, d), d)
res = [dict(zip((d, ), sol))]
point = d.subs(res[0]).limit(old, self.point[i])
newvars[i] = var
newpt[i] = point
elif old not in syms:
del newvars[i], newpt[i]
if not syms and new == self.point[i]:
newvars.extend(syms)
newpt.extend([S.Zero]*len(syms))
else:
return
return Order(newexpr, *zip(newvars, newpt))
开发者ID:kumarkrishna,项目名称:sympy,代码行数:35,代码来源:order.py
示例18: is_strictly_increasing
def is_strictly_increasing(f, interval=S.Reals):
"""
Returns if a function is strictly increasing or not, in the given
``Interval``.
Examples
========
>>> from sympy import is_strictly_increasing
>>> from sympy.abc import x
>>> from sympy import Interval, oo
>>> is_strictly_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval.Ropen(-oo, -2))
True
>>> is_strictly_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval.Lopen(3, oo))
True
>>> is_strictly_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval.open(-2, 3))
False
>>> is_strictly_increasing(-x**2, Interval(0, oo))
False
"""
if len(f.free_symbols) > 1:
raise NotImplementedError('is_strictly_increasing has not yet been '
'implemented for multivariate expressions')
symbol = f.free_symbols.pop()
df = f.diff(symbol)
df_pos_interval = solveset(df > 0, symbol, domain=S.Reals)
return interval.is_subset(df_pos_interval)
开发者ID:atreyv,项目名称:sympy,代码行数:28,代码来源:singularities.py
示例19: singularities
def singularities(expr, sym):
"""
Finds singularities for a function.
Currently supported functions are:
- univariate rational(real or complex) functions
Examples
========
>>> from sympy.calculus.singularities import singularities
>>> from sympy import Symbol, I, sqrt
>>> x = Symbol('x', real=True)
>>> y = Symbol('y', real=False)
>>> singularities(x**2 + x + 1, x)
EmptySet()
>>> singularities(1/(x + 1), x)
{-1}
>>> singularities(1/(y**2 + 1), y)
{-I, I}
>>> singularities(1/(y**3 + 1), y)
{-1, 1/2 - sqrt(3)*I/2, 1/2 + sqrt(3)*I/2}
References
==========
.. [1] http://en.wikipedia.org/wiki/Mathematical_singularity
"""
if not expr.is_rational_function(sym):
raise NotImplementedError("Algorithms finding singularities for"
" non rational functions are not yet"
" implemented")
else:
return solveset(simplify(1/expr), sym)
开发者ID:alexako,项目名称:sympy,代码行数:34,代码来源:singularities.py
示例20: test_nfloat
def test_nfloat():
from sympy.core.basic import _aresame
from sympy.polys.rootoftools import rootof
x = Symbol("x")
eq = x**(S(4)/3) + 4*x**(S(1)/3)/3
assert _aresame(nfloat(eq), x**(S(4)/3) + (4.0/3)*x**(S(1)/3))
assert _aresame(nfloat(eq, exponent=True), x**(4.0/3) + (4.0/3)*x**(1.0/3))
eq = x**(S(4)/3) + 4*x**(x/3)/3
assert _aresame(nfloat(eq), x**(S(4)/3) + (4.0/3)*x**(x/3))
big = 12345678901234567890
# specify precision to match value used in nfloat
Float_big = Float(big, 15)
assert _aresame(nfloat(big), Float_big)
assert _aresame(nfloat(big*x), Float_big*x)
assert _aresame(nfloat(x**big, exponent=True), x**Float_big)
assert nfloat({x: sqrt(2)}) == {x: nfloat(sqrt(2))}
assert nfloat({sqrt(2): x}) == {sqrt(2): x}
assert nfloat(cos(x + sqrt(2))) == cos(x + nfloat(sqrt(2)))
# issue 6342
f = S('x*lamda + lamda**3*(x/2 + 1/2) + lamda**2 + 1/4')
assert not any(a.free_symbols for a in solveset(f.subs(x, -0.139)))
# issue 6632
assert nfloat(-100000*sqrt(2500000001) + 5000000001) == \
9.99999999800000e-11
# issue 7122
eq = cos(3*x**4 + y)*rootof(x**5 + 3*x**3 + 1, 0)
assert str(nfloat(eq, exponent=False, n=1)) == '-0.7*cos(3.0*x**4 + y)'
开发者ID:Lenqth,项目名称:sympy,代码行数:31,代码来源:test_function.py
注:本文中的sympy.solvers.solveset.solveset函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论