本文整理汇总了Python中util._symbol函数的典型用法代码示例。如果您正苦于以下问题:Python _symbol函数的具体用法?Python _symbol怎么用?Python _symbol使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_symbol函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: equation
def equation(self, x='x', y='y'):
"""The equation of the circle.
Parameters
==========
x : str or Symbol, optional
Default value is 'x'.
y : str or Symbol, optional
Default value is 'y'.
Returns
=======
equation : SymPy expression
Examples
========
>>> from sympy import Point, Circle
>>> c1 = Circle(Point(0, 0), 5)
>>> c1.equation()
x**2 + y**2 - 25
"""
x = _symbol(x)
y = _symbol(y)
t1 = (x - self.center.x)**2
t2 = (y - self.center.y)**2
return t1 + t2 - self.major**2
示例2: equation
def equation(self, x='x', y='y'):
"""The equation of the line: ax + by + c.
Parameters
----------
x : str, optional
The name to use for the x-axis, default value is 'x'.
y : str, optional
The name to use for the y-axis, default value is 'y'.
Returns
-------
equation : sympy expression
Examples
--------
>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.equation()
-3*x + 4*y + 3
"""
x, y = _symbol(x), _symbol(y)
p1, p2 = self.points
if p1[0] == p2[0]:
return x - p1[0]
elif p1[1] == p2[1]:
return y - p1[1]
a, b, c = self.coefficients
return simplify(a*x + b*y + c)
示例3: equation
def equation(self, x="x", y="y"):
"""The equation of the ellipse.
Parameters
----------
x : str, optional
Label for the x-axis. Default value is 'x'.
y : str, optional
Label for the y-axis. Default value is 'y'.
Returns
-------
equation : sympy expression
Examples
--------
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(1, 0), 3, 2)
>>> e1.equation()
y**2/4 + (x/3 - 1/3)**2 - 1
"""
x = _symbol(x)
y = _symbol(y)
t1 = ((x - self.center[0]) / self.hradius) ** 2
t2 = ((y - self.center[1]) / self.vradius) ** 2
return t1 + t2 - 1
示例4: plot_interval
def plot_interval(self, parameter='t'):
"""The plot interval for the default geometric plot of line.
Parameters
==========
parameter : str, optional
Default value is 't'.
Returns
=======
plot_interval : list (plot interval)
[parameter, lower_bound, upper_bound]
Examples
========
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.plot_interval()
[t, -5, 5]
"""
t = _symbol(parameter)
return [t, -5, 5]
示例5: plot_interval
def plot_interval(self, parameter='t'):
"""The plot interval for the default geometric plot of the curve.
Parameters
----------
parameter : str or Symbol, optional
Default value is 't';
otherwise the provided symbol is used.
Returns
-------
plot_interval : list (plot interval)
[parameter, lower_bound, upper_bound]
Examples
--------
>>> from sympy import Curve, sin
>>> from sympy.abc import x, t, s
>>> Curve((x, sin(x)), (x, 1, 2)).plot_interval()
[t, 1, 2]
>>> Curve((x, sin(x)), (x, 1, 2)).plot_interval(s)
[s, 1, 2]
"""
t = _symbol(parameter, self.parameter)
return [t] + list(self.limits[1:])
示例6: plot_interval
def plot_interval(self, parameter='t'):
"""The plot interval for the default geometric plot of line. Gives
values that will produce a line that is +/- 5 units long (where a
unit is the distance between the two points that define the line).
Parameters
==========
parameter : str, optional
Default value is 't'.
Returns
=======
plot_interval : list (plot interval)
[parameter, lower_bound, upper_bound]
Examples
========
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.plot_interval()
[t, -5, 5]
"""
t = _symbol(parameter)
return [t, -5, 5]
示例7: arbitrary_point
def arbitrary_point(self, parameter="t"):
"""A parameterized point on the ellipse.
Parameters
----------
parameter : str, optional
Default value is 't'.
Returns
-------
arbitrary_point : Point
Raises
------
ValueError
When `parameter` already appears in the functions.
See Also
--------
Point
Examples
--------
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.arbitrary_point()
Point(3*cos(t), 2*sin(t))
"""
t = _symbol(parameter)
if t.name in (f.name for f in self.free_symbols):
raise ValueError("Symbol %s already appears in object and cannot be used as a parameter." % t.name)
return Point(self.center[0] + self.hradius * C.cos(t), self.center[1] + self.vradius * C.sin(t))
示例8: plot_interval
def plot_interval(self, parameter='t'):
"""The plot interval for the default geometric plot of the Ellipse.
Parameters
==========
parameter : str, optional
Default value is 't'.
Returns
=======
plot_interval : list
[parameter, lower_bound, upper_bound]
Examples
========
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.plot_interval()
[t, -pi, pi]
"""
t = _symbol(parameter)
return [t, -S.Pi, S.Pi]
示例9: arbitrary_point
def arbitrary_point(self, parameter='t'):
"""A parameterized point on the Segment.
Parameters
==========
parameter : str, optional
The name of the parameter which will be used for the parametric
point. The default value is 't'.
Returns
=======
point : Point
Parameters
==========
parameter : str, optional
The name of the parameter which will be used for the parametric
point. The default value is 't'.
Returns
=======
point : Point
Raises
======
ValueError
When ``parameter`` already appears in the Segment's definition.
See Also
========
sympy.geometry.point.Point
Examples
========
>>> from sympy import Point, Segment
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> s1 = Segment(p1, p2)
>>> s1.arbitrary_point()
Point(4*t + 1, 3*t)
"""
t = _symbol(parameter)
if t.name in (f.name for f in self.free_symbols):
raise ValueError('Symbol %s already appears in object and cannot be used as a parameter.' % t.name)
x = simplify(self.p1.x + t*(self.p2.x - self.p1.x))
y = simplify(self.p1.y + t*(self.p2.y - self.p1.y))
return Point(x, y)
示例10: arbitrary_point
def arbitrary_point(self, parameter='t'):
"""
A parameterized point on the curve.
Parameters
==========
parameter : str or Symbol, optional
Default value is 't';
the Curve's parameter is selected with None or self.parameter
otherwise the provided symbol is used.
Returns
=======
arbitrary_point : Point
Raises
======
ValueError
When `parameter` already appears in the functions.
See Also
========
sympy.geometry.point.Point
Examples
========
>>> from sympy import Symbol
>>> from sympy.abc import s
>>> from sympy.geometry import Curve
>>> C = Curve([2*s, s**2], (s, 0, 2))
>>> C.arbitrary_point()
Point(2*t, t**2)
>>> C.arbitrary_point(C.parameter)
Point(2*s, s**2)
>>> C.arbitrary_point(None)
Point(2*s, s**2)
>>> C.arbitrary_point(Symbol('a'))
Point(2*a, a**2)
"""
if parameter is None:
return Point(*self.functions)
tnew = _symbol(parameter, self.parameter)
t = self.parameter
if (tnew.name != t.name and
tnew.name in (f.name for f in self.free_symbols)):
raise ValueError('Symbol %s already appears in object '
'and cannot be used as a parameter.' % tnew.name)
return Point(*[w.subs(t, tnew) for w in self.functions])
示例11: equation
def equation(self, x='x', y='y'):
"""The equation of the line: ax + by + c.
Parameters
==========
x : str, optional
The name to use for the x-axis, default value is 'x'.
y : str, optional
The name to use for the y-axis, default value is 'y'.
Returns
=======
equation : sympy expression
See Also
========
LinearEntity.coefficients
Examples
========
>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.equation()
-3*x + 4*y + 3
"""
x, y = _symbol(x), _symbol(y)
p1, p2 = self.points
if p1.x == p2.x:
return x - p1.x
elif p1.y == p2.y:
return y - p1.y
a, b, c = self.coefficients
return simplify(a*x + b*y + c)
示例12: arbitrary_point
def arbitrary_point(self, parameter='t'):
"""A parameterized point on the polygon.
The parameter, varying from 0 to 1, assigns points to the position on
the perimeter that is that fraction of the total perimeter. So the
point evaluated at t=1/2 would return the point from the first vertex
that is 1/2 way around the polygon.
Parameters
----------
parameter : str, optional
Default value is 't'.
Returns
-------
arbitrary_point : Point
Raises
------
ValueError
When `parameter` already appears in the Polygon's definition.
See Also
--------
Point
Examples
--------
>>> from sympy import Polygon, S, Symbol
>>> t = Symbol('t', real=True)
>>> tri = Polygon((0, 0), (1, 0), (1, 1))
>>> p = tri.arbitrary_point('t')
>>> perimeter = tri.perimeter
>>> s1, s2 = [s.length for s in tri.sides[:2]]
>>> p.subs(t, (s1 + s2/2)/perimeter)
Point(1, 1/2)
"""
t = _symbol(parameter)
if t.name in (f.name for f in self.free_symbols):
raise ValueError('Symbol %s already appears in object and cannot be used as a parameter.' % t.name)
sides = []
perimeter = self.perimeter
perim_fraction_start = 0
for s in self.sides:
side_perim_fraction = s.length/perimeter
perim_fraction_end = perim_fraction_start + side_perim_fraction
pt = s.arbitrary_point(parameter).subs(
t, (t - perim_fraction_start)/side_perim_fraction)
sides.append((pt, (perim_fraction_start <= t < perim_fraction_end)))
perim_fraction_start = perim_fraction_end
return Piecewise(*sides)
示例13: arbitrary_point
def arbitrary_point(self, parameter='t'):
"""A parameterized point on the Segment.
Parameters
----------
parameter : str, optional
The name of the parameter which will be used for the parametric
point. The default value is 't'.
Returns
-------
point : Point
Parameters
----------
parameter : str, optional
The name of the parameter which will be used for the parametric
point. The default value is 't'.
Returns
-------
point : Point
Raises
------
ValueError
When `parameter` already appears in the Segment's definition.
See Also
--------
Point
Examples
--------
>>> from sympy import Point, Segment
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> s1 = Segment(p1, p2)
>>> s1.arbitrary_point()
Point(1 + 4*t, 3*t)
"""
t = _symbol(parameter)
if t.name in (f.name for f in self.free_symbols):
raise ValueError('Symbol %s already appears in object and cannot be used as a parameter.' % t.name)
x = simplify(self.p1[0] + t*(self.p2[0] - self.p1[0]))
y = simplify(self.p1[1] + t*(self.p2[1] - self.p1[1]))
return Point(x, y)
示例14: arbitrary_point
def arbitrary_point(self, parameter='t'):
"""A parameterized point on the Line.
Parameters
==========
parameter : str, optional
The name of the parameter which will be used for the parametric
point. The default value is 't'. When this parameter is 0, the
first point used to define the line will be returned, and when
it is 1 the second point will be returned.
Returns
=======
point : Point
Raises
======
ValueError
When ``parameter`` already appears in the Line's definition.
See Also
========
sympy.geometry.point.Point
Examples
========
>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.arbitrary_point()
Point(4*t + 1, 3*t)
"""
t = _symbol(parameter)
if t.name in (f.name for f in self.free_symbols):
raise ValueError('Symbol %s already appears in object '
'and cannot be used as a parameter.' % t.name)
x = simplify(self.p1.x + t*(self.p2.x - self.p1.x))
y = simplify(self.p1.y + t*(self.p2.y - self.p1.y))
return Point(x, y)
示例15: random_point
def random_point(self):
"""A random point on the ellipse.
Returns
=======
point : Point
See Also
========
sympy.geometry.point.Point
arbitrary_point : Returns parameterized point on ellipse
Notes
-----
A random point may not appear to be on the ellipse, ie, `p in e` may
return False. This is because the coordinates of the point will be
floating point values, and when these values are substituted into the
equation for the ellipse the result may not be zero because of floating
point rounding error.
Examples
========
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> p1 = e1.random_point()
>>> # a random point may not appear to be on the ellipse because of
>>> # floating point rounding error
>>> p1 in e1 # doctest: +SKIP
True
>>> p1 # doctest +ELLIPSIS
Point(...)
"""
from random import random
t = _symbol("t")
x, y = self.arbitrary_point(t).args
# get a random value in [-pi, pi)
subs_val = float(S.Pi) * (2 * random() - 1)
return Point(x.subs(t, subs_val), y.subs(t, subs_val))