本文整理汇总了Python中sympy.core.basic.Basic.sqrt方法的典型用法代码示例。如果您正苦于以下问题:Python Basic.sqrt方法的具体用法?Python Basic.sqrt怎么用?Python Basic.sqrt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.core.basic.Basic
的用法示例。
在下文中一共展示了Basic.sqrt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: intersection
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sqrt [as 别名]
def intersection(self, o):
if isinstance(o, Circle):
dx,dy = o._c - self.center
d = Basic.sqrt( simplify(dy**2 + dx**2) )
a = simplify((self.radius**2 - o.radius**2 + d**2) / (2*d))
x2 = self.center[0] + (dx * a/d)
y2 = self.center[1] + (dy * a/d)
h = Basic.sqrt( simplify(self.radius**2 - a**2) )
rx = -dy * (h/d)
ry = dx * (h/d)
xi_1 = simplify(x2 + rx)
xi_2 = simplify(x2 - rx)
yi_1 = simplify(y2 + ry)
yi_2 = simplify(y2 - ry)
ret = [Point(xi_1, yi_1)]
if xi_1 != xi_2 or yi_1 != yi_2:
ret.append(Point(xi_2, yi_2))
return ret
elif isinstance(o, Ellipse):
a, b, r = o.hradius, o.vradius, self.radius
x = a*Basic.sqrt(simplify((r**2 - b**2)/(a**2 - b**2)))
y = b*Basic.sqrt(simplify((a**2 - r**2)/(a**2 - b**2)))
return list(set([Point(x,y), Point(x,-y), Point(-x,y), Point(-x,-y)]))
return Ellipse.intersection(self, o)
示例2: _eval_apply
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sqrt [as 别名]
def _eval_apply(self, arg):
arg = Basic.sympify(arg)
if isinstance(arg, Basic.Number):
if isinstance(arg, Basic.NaN):
return S.NaN
#elif isinstance(arg, Basic.Zero):
# return S.ComplexInfinity
elif arg.is_negative:
return -self(-arg)
else:
i_coeff = arg.as_coefficient(S.ImaginaryUnit)
if i_coeff is not None:
return -S.ImaginaryUnit * Basic.coth(i_coeff)
else:
pi_coeff = arg.as_coefficient(S.Pi)
if pi_coeff is not None:
#if pi_coeff.is_integer:
# return S.ComplexInfinity
if isinstance(pi_coeff, Basic.Rational):
cst_table = {
2 : S.Zero,
3 : 1 / Basic.sqrt(3),
4 : S.One,
6 : Basic.sqrt(3)
}
try:
result = cst_table[pi_coeff.q]
if (2*pi_coeff.p // pi_coeff.q) % 4 in (1, 3):
return -result
else:
return result
except KeyError:
pass
coeff, terms = arg.as_coeff_terms()
if coeff.is_negative:
return -self(-arg)
示例3: _eval_apply
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sqrt [as 别名]
def _eval_apply(self, arg):
if isinstance(arg, Basic.NaN):
return S.NaN
if arg.is_positive: return arg
if arg.is_negative: return -arg
coeff, terms = arg.as_coeff_terms()
if not isinstance(coeff, Basic.One):
return self(coeff) * self(Basic.Mul(*terms))
if arg.is_real is False:
return Basic.sqrt( (arg * arg.conjugate()).expand() )
return
示例4: distance
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sqrt [as 别名]
def distance(p1, p2):
"""
Get the Euclidean distance between two points.
Example:
========
>>> p1,p2 = Point(1, 1), Point(4, 5)
>>> Point.distance(p1, p2)
5
"""
return Basic.sqrt( sum([(a-b)**2 for a,b in zip(p1,p2)]) )
示例5: taylor_term
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sqrt [as 别名]
def taylor_term(self, n, x, *previous_terms):
if n < 0 or n % 2 == 0:
return S.Zero
else:
x = Basic.sympify(x)
k = (n - 1)/2
if len(previous_terms) > 2:
return -previous_terms[-2] * x**2 * (n-2)/(n*k)
else:
return 2*(-1)**k * x**n/(n*Basic.Factorial(k)*Basic.sqrt(S.Pi))
示例6: foci
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sqrt [as 别名]
def foci(self):
"""The foci of the ellipse, if the radii are numerical."""
c = self.center
if self.hradius == self.vradius:
return c
hr, vr = self.hradius, self.vradius
if hr.atoms(type=Basic.Symbol) or vr.atoms(type=Basic.Symbol):
raise Exception("foci can only be determined on non-symbolic radii")
v = Basic.sqrt(abs(vr**2 - hr**2))
if hr < vr:
return (c+Point(0, -v), c+Point(0, v))
else:
return (c+Point(-v, 0), c+Point(v, 0))
示例7: _do_line_intersection
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sqrt [as 别名]
def _do_line_intersection(self, o):
"""
Find the intersection of a LinearEntity and the ellipse. Makes no
regards to what the LinearEntity is because it assumes a Line. To
ensure correct intersection results one must invoke intersection()
to remove bad results.
"""
def dot(p1, p2):
sum = 0
for ind in xrange(0, len(p1)):
sum += p1[ind] * p2[ind]
return simplify(sum)
hr_sq = self.hradius ** 2
vr_sq = self.vradius ** 2
lp = o.points
ldir = lp[1] - lp[0]
diff = lp[0] - self.center
mdir = (ldir[0] / hr_sq, ldir[1] / vr_sq)
mdiff = (diff[0] / hr_sq, diff[1] / vr_sq)
a = dot(ldir, mdir)
b = dot(ldir, mdiff)
c = dot(diff, mdiff) - 1
det = simplify(b*b - a*c);
result = []
if det == 0:
t = -b / a
result.append( lp[0] + (lp[1] - lp[0]) * t )
else:
is_good = True
try:
is_good = (det > 0)
except NotImplementedError: #symbolic, allow
is_good = True
if is_good:
root = Basic.sqrt(det)
t_a = (-b - root) / a
t_b = (-b + root) / a
result.append( lp[0] + (lp[1] - lp[0]) * t_a )
result.append( lp[0] + (lp[1] - lp[0]) * t_b )
return result
示例8: fdiff
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sqrt [as 别名]
def fdiff(self, argindex=1):
if argindex == 1:
return 2*Basic.exp(-self[0]**2)/Basic.sqrt(S.Pi)
else:
raise ArgumentIndexError(self, argindex)