本文整理汇总了Python中sympy.vector.functions.express函数的典型用法代码示例。如果您正苦于以下问题:Python express函数的具体用法?Python express怎么用?Python express使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了express函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cross
def cross(self, vect):
"""
Represents the cross product between this operator and a given
vector - equal to the curl of the vector field.
Parameters
==========
vect : Vector
The vector whose curl is to be calculated.
Examples
========
>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> v = C.x*C.y*C.z * (C.i + C.j + C.k)
>>> C.delop ^ v
(-C.x*C.y + C.x*C.z)*C.i + (C.x*C.y - C.y*C.z)*C.j + (-C.x*C.z + C.y*C.z)*C.k
>>> C.delop.cross(C.i)
0
"""
vectx = express(vect.dot(self._i), self.system)
vecty = express(vect.dot(self._j), self.system)
vectz = express(vect.dot(self._k), self.system)
outvec = Vector.zero
outvec += (diff(vectz, self._y) - diff(vecty, self._z)) * self._i
outvec += (diff(vectx, self._z) - diff(vectz, self._x)) * self._j
outvec += (diff(vecty, self._x) - diff(vectx, self._y)) * self._k
return outvec
示例2: curl
def curl(vect, coord_sys=None, doit=True):
"""
Returns the curl of a vector field computed wrt the base scalars
of the given coordinate system.
Parameters
==========
vect : Vector
The vector operand
coord_sys : CoordSys3D
The coordinate system to calculate the gradient in.
Deprecated since version 1.1
doit : bool
If True, the result is returned after calling .doit() on
each component. Else, the returned expression contains
Derivative instances
Examples
========
>>> from sympy.vector import CoordSys3D, curl
>>> R = CoordSys3D('R')
>>> v1 = R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
>>> curl(v1)
0
>>> v2 = R.x*R.y*R.z*R.i
>>> curl(v2)
R.x*R.y*R.j + (-R.x*R.z)*R.k
"""
coord_sys = _get_coord_sys_from_expr(vect, coord_sys)
if coord_sys is None:
return Vector.zero
else:
from sympy.vector.functions import express
vectx = express(vect.dot(coord_sys._i), coord_sys, variables=True)
vecty = express(vect.dot(coord_sys._j), coord_sys, variables=True)
vectz = express(vect.dot(coord_sys._k), coord_sys, variables=True)
outvec = Vector.zero
outvec += (Derivative(vectz * coord_sys._h3, coord_sys._y) -
Derivative(vecty * coord_sys._h2, coord_sys._z)) * coord_sys._i / (coord_sys._h2 * coord_sys._h3)
outvec += (Derivative(vectx * coord_sys._h1, coord_sys._z) -
Derivative(vectz * coord_sys._h3, coord_sys._x)) * coord_sys._j / (coord_sys._h1 * coord_sys._h3)
outvec += (Derivative(vecty * coord_sys._h2, coord_sys._x) -
Derivative(vectx * coord_sys._h1, coord_sys._y)) * coord_sys._k / (coord_sys._h2 * coord_sys._h1)
if doit:
return outvec.doit()
return outvec
示例3: test_coordinate_vars
def test_coordinate_vars():
"""
Tests the coordinate variables functionality with respect to
reorientation of coordinate systems.
"""
A = CoordSysCartesian('A')
assert BaseScalar('Ax', 0, A, ' ', ' ') == A.x
assert BaseScalar('Ay', 1, A, ' ', ' ') == A.y
assert BaseScalar('Az', 2, A, ' ', ' ') == A.z
assert BaseScalar('Ax', 0, A, ' ', ' ').__hash__() == A.x.__hash__()
assert isinstance(A.x, BaseScalar) and \
isinstance(A.y, BaseScalar) and \
isinstance(A.z, BaseScalar)
assert A.scalar_map(A) == {A.x: A.x, A.y: A.y, A.z: A.z}
assert A.x.system == A
B = A.orient_new_axis('B', q, A.k)
assert B.scalar_map(A) == {B.z: A.z, B.y: -A.x*sin(q) + A.y*cos(q),
B.x: A.x*cos(q) + A.y*sin(q)}
assert A.scalar_map(B) == {A.x: B.x*cos(q) - B.y*sin(q),
A.y: B.x*sin(q) + B.y*cos(q), A.z: B.z}
assert express(B.x, A, variables=True) == A.x*cos(q) + A.y*sin(q)
assert express(B.y, A, variables=True) == -A.x*sin(q) + A.y*cos(q)
assert express(B.z, A, variables=True) == A.z
assert express(B.x*B.y*B.z, A, variables=True) == \
A.z*(-A.x*sin(q) + A.y*cos(q))*(A.x*cos(q) + A.y*sin(q))
assert express(B.x*B.i + B.y*B.j + B.z*B.k, A) == \
(B.x*cos(q) - B.y*sin(q))*A.i + (B.x*sin(q) + \
B.y*cos(q))*A.j + B.z*A.k
assert simplify(express(B.x*B.i + B.y*B.j + B.z*B.k, A, \
variables=True)) == \
A.x*A.i + A.y*A.j + A.z*A.k
assert express(A.x*A.i + A.y*A.j + A.z*A.k, B) == \
(A.x*cos(q) + A.y*sin(q))*B.i + \
(-A.x*sin(q) + A.y*cos(q))*B.j + A.z*B.k
assert simplify(express(A.x*A.i + A.y*A.j + A.z*A.k, B, \
variables=True)) == \
B.x*B.i + B.y*B.j + B.z*B.k
N = B.orient_new_axis('N', -q, B.k)
assert N.scalar_map(A) == \
{N.x: A.x, N.z: A.z, N.y: A.y}
C = A.orient_new_axis('C', q, A.i + A.j + A.k)
mapping = A.scalar_map(C)
assert mapping[A.x] == 2*C.x*cos(q)/3 + C.x/3 - \
2*C.y*sin(q + pi/6)/3 + C.y/3 - 2*C.z*cos(q + pi/3)/3 + C.z/3
assert mapping[A.y] == -2*C.x*cos(q + pi/3)/3 + \
C.x/3 + 2*C.y*cos(q)/3 + C.y/3 - 2*C.z*sin(q + pi/6)/3 + C.z/3
assert mapping[A.z] == -2*C.x*sin(q + pi/6)/3 + C.x/3 - \
2*C.y*cos(q + pi/3)/3 + C.y/3 + 2*C.z*cos(q)/3 + C.z/3
D = A.locate_new('D', a*A.i + b*A.j + c*A.k)
assert D.scalar_map(A) == {D.z: A.z - c, D.x: A.x - a, D.y: A.y - b}
E = A.orient_new_axis('E', a, A.k, a*A.i + b*A.j + c*A.k)
assert A.scalar_map(E) == {A.z: E.z + c,
A.x: E.x*cos(a) - E.y*sin(a) + a,
A.y: E.x*sin(a) + E.y*cos(a) + b}
assert E.scalar_map(A) == {E.x: (A.x - a)*cos(a) + (A.y - b)*sin(a),
E.y: (-A.x + a)*sin(a) + (A.y - b)*cos(a),
E.z: A.z - c}
F = A.locate_new('F', Vector.zero)
assert A.scalar_map(F) == {A.z: F.z, A.x: F.x, A.y: F.y}
示例4: __call__
def __call__(self, scalar_field):
"""
Represents the gradient of the given scalar field.
Parameters
==========
scalar_field : SymPy expression
The scalar field to calculate the gradient of.
Examples
========
>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> C.delop(C.x*C.y*C.z)
C.y*C.z*C.i + C.x*C.z*C.j + C.x*C.y*C.k
"""
scalar_field = express(scalar_field, self.system,
variables = True)
vx = diff(scalar_field, self._x)
vy = diff(scalar_field, self._y)
vz = diff(scalar_field, self._z)
return vx*self._i + vy*self._j + vz*self._k
示例5: express_coordinates
def express_coordinates(self, coordinate_system):
"""
Returns the Cartesian/rectangular coordinates of this point
wrt the origin of the given CoordSysCartesian instance.
Parameters
==========
coordinate_system : CoordSysCartesian
The coordinate system to express the coordinates of this
Point in.
Examples
========
>>> from sympy.vector import Point, CoordSysCartesian
>>> N = CoordSysCartesian('N')
>>> p1 = N.origin.locate_new('p1', 10 * N.i)
>>> p2 = p1.locate_new('p2', 5 * N.j)
>>> p2.express_coordinates(N)
(10, 5, 0)
"""
#Determine the position vector
pos_vect = self.position_wrt(coordinate_system.origin)
#Express it in the given coordinate system
pos_vect = trigsimp(express(pos_vect, coordinate_system,
variables = True))
coords = []
for vect in coordinate_system.base_vectors():
coords.append(pos_vect.dot(vect))
return tuple(coords)
示例6: test_vector
def test_vector():
"""
Tests the effects of orientation of coordinate systems on
basic vector operations.
"""
N = CoordSysCartesian("N")
A = N.orient_new_axis("A", q1, N.k)
B = A.orient_new_axis("B", q2, A.i)
C = B.orient_new_axis("C", q3, B.j)
# Test to_matrix
v1 = a * N.i + b * N.j + c * N.k
assert v1.to_matrix(A) == Matrix([[a * cos(q1) + b * sin(q1)], [-a * sin(q1) + b * cos(q1)], [c]])
# Test dot
assert N.i.dot(A.i) == cos(q1)
assert N.i.dot(A.j) == -sin(q1)
assert N.i.dot(A.k) == 0
assert N.j.dot(A.i) == sin(q1)
assert N.j.dot(A.j) == cos(q1)
assert N.j.dot(A.k) == 0
assert N.k.dot(A.i) == 0
assert N.k.dot(A.j) == 0
assert N.k.dot(A.k) == 1
assert N.i.dot(A.i + A.j) == -sin(q1) + cos(q1) == (A.i + A.j).dot(N.i)
assert A.i.dot(C.i) == cos(q3)
assert A.i.dot(C.j) == 0
assert A.i.dot(C.k) == sin(q3)
assert A.j.dot(C.i) == sin(q2) * sin(q3)
assert A.j.dot(C.j) == cos(q2)
assert A.j.dot(C.k) == -sin(q2) * cos(q3)
assert A.k.dot(C.i) == -cos(q2) * sin(q3)
assert A.k.dot(C.j) == sin(q2)
assert A.k.dot(C.k) == cos(q2) * cos(q3)
# Test cross
assert N.i.cross(A.i) == sin(q1) * A.k
assert N.i.cross(A.j) == cos(q1) * A.k
assert N.i.cross(A.k) == -sin(q1) * A.i - cos(q1) * A.j
assert N.j.cross(A.i) == -cos(q1) * A.k
assert N.j.cross(A.j) == sin(q1) * A.k
assert N.j.cross(A.k) == cos(q1) * A.i - sin(q1) * A.j
assert N.k.cross(A.i) == A.j
assert N.k.cross(A.j) == -A.i
assert N.k.cross(A.k) == Vector.zero
assert N.i.cross(A.i) == sin(q1) * A.k
assert N.i.cross(A.j) == cos(q1) * A.k
assert N.i.cross(A.i + A.j) == sin(q1) * A.k + cos(q1) * A.k
assert (A.i + A.j).cross(N.i) == (-sin(q1) - cos(q1)) * N.k
assert A.i.cross(C.i) == sin(q3) * C.j
assert A.i.cross(C.j) == -sin(q3) * C.i + cos(q3) * C.k
assert A.i.cross(C.k) == -cos(q3) * C.j
assert C.i.cross(A.i) == (-sin(q3) * cos(q2)) * A.j + (-sin(q2) * sin(q3)) * A.k
assert C.j.cross(A.i) == (sin(q2)) * A.j + (-cos(q2)) * A.k
assert express(C.k.cross(A.i), C).trigsimp() == cos(q3) * C.j
示例7: directional_derivative
def directional_derivative(field):
field = express(field, other.system, variables = True)
out = self.dot(other._i) * df(field, other._x)
out += self.dot(other._j) * df(field, other._y)
out += self.dot(other._k) * df(field, other._z)
if out == 0 and isinstance(field, Vector):
out = Vector.zero
return out
示例8: cross
def cross(self, vect, doit=False):
"""
Represents the cross product between this operator and a given
vector - equal to the curl of the vector field.
Parameters
==========
vect : Vector
The vector whose curl is to be calculated.
doit : bool
If True, the result is returned after calling .doit() on
each component. Else, the returned expression contains
Derivative instances
Examples
========
>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> v = C.x*C.y*C.z * (C.i + C.j + C.k)
>>> C.delop.cross(v, doit = True)
(-C.x*C.y + C.x*C.z)*C.i + (C.x*C.y - C.y*C.z)*C.j +
(-C.x*C.z + C.y*C.z)*C.k
>>> (C.delop ^ C.i).doit()
0
"""
vectx = express(vect.dot(self._i), self.system, variables=True)
vecty = express(vect.dot(self._j), self.system, variables=True)
vectz = express(vect.dot(self._k), self.system, variables=True)
outvec = Vector.zero
outvec += (Derivative(vectz, self._y) -
Derivative(vecty, self._z)) * self._i
outvec += (Derivative(vectx, self._z) -
Derivative(vectz, self._x)) * self._j
outvec += (Derivative(vecty, self._x) -
Derivative(vectx, self._y)) * self._k
if doit:
return outvec.doit()
return outvec
示例9: _diff_conditional
def _diff_conditional(expr, base_scalar):
"""
First re-expresses expr in the system that base_scalar belongs to.
If base_scalar appears in the re-expressed form, differentiates
it wrt base_scalar.
Else, returns S(0)
"""
new_expr = express(expr, base_scalar.system, variables = True)
if base_scalar in new_expr.atoms(BaseScalar):
return Derivative(new_expr, base_scalar)
return S(0)
示例10: _diff_conditional
def _diff_conditional(expr, base_scalar, coeff_1, coeff_2):
"""
First re-expresses expr in the system that base_scalar belongs to.
If base_scalar appears in the re-expressed form, differentiates
it wrt base_scalar.
Else, returns S(0)
"""
from sympy.vector.functions import express
new_expr = express(expr, base_scalar.system, variables=True)
if base_scalar in new_expr.atoms(BaseScalar):
return Derivative(coeff_1 * coeff_2 * new_expr, base_scalar)
return S(0)
示例11: test_coordinate_vars
def test_coordinate_vars():
"""
Tests the coordinate variables functionality with respect to
reorientation of coordinate systems.
"""
assert BaseScalar('Ax', 0, A) == A.x
assert BaseScalar('Ay', 1, A) == A.y
assert BaseScalar('Az', 2, A) == A.z
assert BaseScalar('Ax', 0, A).__hash__() == A.x.__hash__()
assert isinstance(A.x, BaseScalar) and \
isinstance(A.y, BaseScalar) and \
isinstance(A.z, BaseScalar)
assert A.scalar_map(A) == {A.x: A.x, A.y: A.y, A.z: A.z}
assert A.x.system == A
B = A.orient_new('B', 'Axis', [q, A.k])
assert B.scalar_map(A) == {B.z: A.z, B.y: -A.x*sin(q) + A.y*cos(q),
B.x: A.x*cos(q) + A.y*sin(q)}
assert A.scalar_map(B) == {A.x: B.x*cos(q) - B.y*sin(q),
A.y: B.x*sin(q) + B.y*cos(q), A.z: B.z}
assert express(B.x, A, variables=True) == A.x*cos(q) + A.y*sin(q)
assert express(B.y, A, variables=True) == -A.x*sin(q) + A.y*cos(q)
assert express(B.z, A, variables=True) == A.z
assert express(B.x*B.y*B.z, A, variables=True) == \
A.z*(-A.x*sin(q) + A.y*cos(q))*(A.x*cos(q) + A.y*sin(q))
assert express(B.x*B.i + B.y*B.j + B.z*B.k, A) == \
(B.x*cos(q) - B.y*sin(q))*A.i + (B.x*sin(q) + \
B.y*cos(q))*A.j + B.z*A.k
assert simplify(express(B.x*B.i + B.y*B.j + B.z*B.k, A, \
variables=True)) == \
A.x*A.i + A.y*A.j + A.z*A.k
assert express(A.x*A.i + A.y*A.j + A.z*A.k, B) == \
(A.x*cos(q) + A.y*sin(q))*B.i + \
(-A.x*sin(q) + A.y*cos(q))*B.j + A.z*B.k
assert simplify(express(A.x*A.i + A.y*A.j + A.z*A.k, B, \
variables=True)) == \
B.x*B.i + B.y*B.j + B.z*B.k
N = B.orient_new('N', 'Axis', [-q, B.k])
assert N.scalar_map(A) == \
{N.x: A.x, N.z: A.z, N.y: A.y}
C = A.orient_new('C', 'Axis', [q, A.i + A.j + A.k])
mapping = A.scalar_map(C)
assert mapping[A.x] == 2*C.x*cos(q)/3 + C.x/3 - \
2*C.y*sin(q + pi/6)/3 + C.y/3 - 2*C.z*cos(q + pi/3)/3 + C.z/3
assert mapping[A.y] == -2*C.x*cos(q + pi/3)/3 + \
C.x/3 + 2*C.y*cos(q)/3 + C.y/3 - 2*C.z*sin(q + pi/6)/3 + C.z/3
assert mapping[A.z] == -2*C.x*sin(q + pi/6)/3 + C.x/3 - \
2*C.y*cos(q + pi/3)/3 + C.y/3 + 2*C.z*cos(q)/3 + C.z/3
示例12: directional_derivative
def directional_derivative(field):
from sympy.vector.operators import _get_coord_sys_from_expr
coord_sys = _get_coord_sys_from_expr(field)
if coord_sys is not None:
field = express(field, coord_sys, variables=True)
out = self.dot(coord_sys._i) * df(field, coord_sys._x)
out += self.dot(coord_sys._j) * df(field, coord_sys._y)
out += self.dot(coord_sys._k) * df(field, coord_sys._z)
if out == 0 and isinstance(field, Vector):
out = Vector.zero
return out
elif isinstance(field, Vector) :
return Vector.zero
else:
return S(0)
示例13: gradient
def gradient(scalar_field, coord_sys=None, doit=True):
"""
Returns the vector gradient of a scalar field computed wrt the
base scalars of the given coordinate system.
Parameters
==========
scalar_field : SymPy Expr
The scalar field to compute the gradient of
coord_sys : CoordSys3D
The coordinate system to calculate the gradient in
Deprecated since version 1.1
doit : bool
If True, the result is returned after calling .doit() on
each component. Else, the returned expression contains
Derivative instances
Examples
========
>>> from sympy.vector import CoordSys3D, gradient
>>> R = CoordSys3D('R')
>>> s1 = R.x*R.y*R.z
>>> gradient(s1)
R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
>>> s2 = 5*R.x**2*R.z
>>> gradient(s2)
10*R.x*R.z*R.i + 5*R.x**2*R.k
"""
coord_sys = _get_coord_sys_from_expr(scalar_field, coord_sys)
if coord_sys is None:
return Vector.zero
else:
from sympy.vector.functions import express
scalar_field = express(scalar_field, coord_sys,
variables=True)
vx = Derivative(scalar_field, coord_sys._x) / coord_sys._h1
vy = Derivative(scalar_field, coord_sys._y) / coord_sys._h2
vz = Derivative(scalar_field, coord_sys._z) / coord_sys._h3
if doit:
return (vx * coord_sys._i + vy * coord_sys._j + vz * coord_sys._k).doit()
return vx * coord_sys._i + vy * coord_sys._j + vz * coord_sys._k
示例14: _orient_axis
def _orient_axis(amounts, rot_order, parent):
"""
Helper method for orientation using Axis method.
"""
if not rot_order == "":
raise TypeError("Axis orientation takes no" + "rotation order")
if not (isinstance(amounts, (list, tuple)) and (len(amounts) == 2)):
raise TypeError("Amounts should be of length 2")
theta = amounts[0]
axis = amounts[1]
axis = express(axis, parent).normalize()
axis = axis.to_matrix(parent)
parent_orient = (
(eye(3) - axis * axis.T) * cos(theta)
+ Matrix([[0, -axis[2], axis[1]], [axis[2], 0, -axis[0]], [-axis[1], axis[0], 0]]) * sin(theta)
+ axis * axis.T
)
return parent_orient
示例15: gradient
def gradient(self, scalar_field, doit=False):
"""
Returns the gradient of the given scalar field, as a
Vector instance.
Parameters
==========
scalar_field : SymPy expression
The scalar field to calculate the gradient of.
doit : bool
If True, the result is returned after calling .doit() on
each component. Else, the returned expression contains
Derivative instances
Examples
========
>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> C.delop.gradient(9)
(Derivative(9, C.x))*C.i + (Derivative(9, C.y))*C.j +
(Derivative(9, C.z))*C.k
>>> C.delop(C.x*C.y*C.z).doit()
C.y*C.z*C.i + C.x*C.z*C.j + C.x*C.y*C.k
"""
scalar_field = express(scalar_field, self.system,
variables=True)
vx = Derivative(scalar_field, self._x)
vy = Derivative(scalar_field, self._y)
vz = Derivative(scalar_field, self._z)
if doit:
return (vx * self._i + vy * self._j + vz * self._k).doit()
return vx * self._i + vy * self._j + vz * self._k