本文整理汇总了Python中sympy.matrices.Matrix.dot方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.dot方法的具体用法?Python Matrix.dot怎么用?Python Matrix.dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.matrices.Matrix
的用法示例。
在下文中一共展示了Matrix.dot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: distance
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import dot [as 别名]
def distance(self, o):
"""Distance beteen the plane and another geometric entity.
Parameters
==========
Point3D, LinearEntity3D, Plane.
Returns
=======
distance
Notes
=====
This method accepts only 3D entities as it's parameter, but if you want
to calculate the distance between a 2D entity and a plane you should
first convert to a 3D entity by projecting onto a desired plane and
then proceed to calculate the distance.
Examples
========
>>> from sympy import Point, Point3D, Line, Line3D, Plane
>>> a = Plane(Point3D(1, 1, 1), normal_vector=(1, 1, 1))
>>> b = Point3D(1, 2, 3)
>>> a.distance(b)
sqrt(3)
>>> c = Line3D(Point3D(2, 3, 1), Point3D(1, 2, 2))
>>> a.distance(c)
0
"""
from sympy.geometry.line3d import LinearEntity3D
x, y, z = map(Dummy, 'xyz')
if self.intersection(o) != []:
return S.Zero
if isinstance(o, Point3D):
x, y, z = map(Dummy, 'xyz')
k = self.equation(x, y, z)
a, b, c = [k.coeff(i) for i in (x, y, z)]
d = k.xreplace({x: o.args[0], y: o.args[1], z: o.args[2]})
t = abs(d/sqrt(a**2 + b**2 + c**2))
return t
if isinstance(o, LinearEntity3D):
a, b = o.p1, self.p1
c = Matrix(a.direction_ratio(b))
d = Matrix(self.normal_vector)
e = c.dot(d)
f = sqrt(sum([i**2 for i in self.normal_vector]))
return abs(e / f)
if isinstance(o, Plane):
a, b = o.p1, self.p1
c = Matrix(a.direction_ratio(b))
d = Matrix(self.normal_vector)
e = c.dot(d)
f = sqrt(sum([i**2 for i in self.normal_vector]))
return abs(e / f)
示例2: angle_between
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import dot [as 别名]
def angle_between(self, o):
"""Angle between the plane and other geometric entity.
Parameters
==========
LinearEntity3D, Plane.
Returns
=======
angle : angle in radians
Notes
=====
This method accepts only 3D entities as it's parameter, but if you want
to calculate the angle between a 2D entity and a plane you should
first convert to a 3D entity by projecting onto a desired plane and
then proceed to calculate the angle.
Examples
========
>>> from sympy import Point3D, Line3D, Plane
>>> a = Plane(Point3D(1, 2, 2), normal_vector=(1, 2, 3))
>>> b = Line3D(Point3D(1, 3, 4), Point3D(2, 2, 2))
>>> a.angle_between(b)
-asin(sqrt(21)/6)
"""
from sympy.geometry.line3d import LinearEntity3D
if isinstance(o, LinearEntity3D):
a = Matrix(self.normal_vector)
b = Matrix(o.direction_ratio)
c = a.dot(b)
d = sqrt(sum([i ** 2 for i in self.normal_vector]))
e = sqrt(sum([i ** 2 for i in o.direction_ratio]))
return asin(c / (d * e))
if isinstance(o, Plane):
a = Matrix(self.normal_vector)
b = Matrix(o.normal_vector)
c = a.dot(b)
d = sqrt(sum([i ** 2 for i in self.normal_vector]))
e = sqrt(sum([i ** 2 for i in o.normal_vector]))
return acos(c / (d * e))
示例3: are_coplanar
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import dot [as 别名]
def are_coplanar(*points):
"""
This function tests whether passed points are coplanar or not.
It uses the fact that the triple scalar product of three vectors
vanishes if the vectors are coplanar. Which means that the volume
of the solid described by them will have to be zero for coplanarity.
Parameters
==========
A set of points 3D points
Returns
=======
boolean
Examples
========
>>> from sympy import Point3D
>>> p1 = Point3D(1, 2, 2)
>>> p2 = Point3D(2, 7, 2)
>>> p3 = Point3D(0, 0, 2)
>>> p4 = Point3D(1, 1, 2)
>>> p5 = Point3D(1, 2, 2)
>>> p1.are_coplanar(p2, p3, p4, p5)
True
>>> p6 = Point3D(0, 1, 3)
>>> p1.are_coplanar(p2, p3, p4, p5, p6)
False
"""
if not all(isinstance(p, Point3D) for p in points):
raise TypeError('Must pass only 3D Point objects')
if(len(points) < 4):
return True # These cases are always True
points = list(set(points))
for i in range(len(points) - 3):
pv1 = [j - k for j, k in zip(points[i].args, \
points[i + 1].args)]
pv2 = [j - k for j, k in zip(points[i + 1].args,
points[i + 2].args)]
pv3 = [j - k for j, k in zip(points[i + 2].args,
points[i + 3].args)]
pv1, pv2, pv3 = Matrix(pv1), Matrix(pv2), Matrix(pv3)
stp = pv1.dot(pv2.cross(pv3))
if stp != 0:
return False
return True
示例4: verification_of_sufficient_second_order_conditions
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import dot [as 别名]
def verification_of_sufficient_second_order_conditions(K, df, x, l):
if not K:
print "The sufficient optimality condition of second kind is made."
else:
ddf = []
for xi in x:
ddf.append([ddfi.diff(xi) for ddfi in df])
ddf = Matrix(ddf)
ll = Matrix(l)
if Matrix(ddf.dot(ll.T)).dot(ll).subs(K) > 0:
print "The sufficient optimality condition of second kind is made."
else:
print "The sufficient optimality condition of second kind is not made."
return
示例5: is_perpendicular
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import dot [as 别名]
def is_perpendicular(self, l):
"""is the given geometric entity perpendicualar to the given plane?
Parameters
==========
LinearEntity3D or Plane
Returns
=======
Boolean
Examples
========
>>> from sympy import Plane, Point3D
>>> a = Plane(Point3D(1,4,6), normal_vector=(2, 4, 6))
>>> b = Plane(Point3D(2, 2, 2), normal_vector=(-1, 2, -1))
>>> a.is_perpendicular(b)
True
"""
from sympy.geometry.line3d import LinearEntity3D
if isinstance(l, LinearEntity3D):
a = Matrix(l.direction_ratio)
b = Matrix(self.normal_vector)
if a.cross(b).is_zero:
return True
else:
return False
elif isinstance(l, Plane):
a = Matrix(l.normal_vector)
b = Matrix(self.normal_vector)
if a.dot(b) == 0:
return True
else:
return False
else:
return False
示例6: distance
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import dot [as 别名]
def distance(self, o):
"""Distance beteen the plane and another geometric entity.
Parameters
==========
Point3D, LinearEntity3D, Plane.
Returns
=======
distance
Notes
=====
This method accepts only 3D entities as it's parameter, but if you want
to calculate the distance between a 2D entity and a plane you should
first convert to a 3D entity by projecting onto a desired plane and
then proceed to calculate the distance.
Examples
========
>>> from sympy import Point, Point3D, Line, Line3D, Plane
>>> a = Plane(Point3D(1, 1, 1), normal_vector=[1, 1, 1])
>>> b = Point3D(1, 2, 3)
>>> a.distance(b)
sqrt(3)
>>> c = Line3D(Point3D(2, 3, 1), Point3D(1, 2, 2))
>>> a.distance(c)
0
"""
from sympy.geometry.line3d import LinearEntity3D
x, y, z = symbols("x y z")
if self.intersection(o) != []:
return S.Zero
if isinstance(o, Point3D):
k = self.equation(x, y, z)
const = [i for i in k.args if i.is_constant() is True]
a, b, c = k.coeff(x), k.coeff(y), k.coeff(z)
if const != []:
d = a*o.x + b*o.y + c*o.z + const.pop()
t = sqrt(a**2 + b**2 + c**2)
return abs(d / t)
else:
d = a*o.x + b*o.y + c*o.z
t = sqrt(a**2 + b**2 + c**2)
return abs(d / t)
if isinstance(o, LinearEntity3D):
a, b = o.p1, self.p1
c = Matrix(a.direction_ratio(b))
d = Matrix(self.normal_vector)
e = c.dot(d)
f = sqrt(sum([i**2 for i in self.normal_vector]))
return abs(e / f)
if isinstance(o, Plane):
a, b = o.p1, self.p1
c = Matrix(a.direction_ratio(b))
d = Matrix(self.normal_vector)
e = c.dot(d)
f = sqrt(sum([i**2 for i in self.normal_vector]))
return abs(e / f)
示例7: zip
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import dot [as 别名]
def СheckСonditions(x, plan, a, f, g, l):
plan_ = []
for obj in zip(x, plan):
plan_.append(obj)
g_plan = array([elem.subs(plan_) for elem in g])
if (g_plan <= 0.0).all():
print(accessedPlanLabel.format(plan))
else:
raise Exception(errorMessage)
return
I0 = [i for i, gi in enumerate(g_plan) if gi == 0.0]
# подготовим таблицу с частными производными по каждой переменной
matrix = zeros((len(x), len(I0)))
for i, index in enumerate(I0):
matrix[:, i] = [g[index].diff(xi).subs(plan_) for xi in x]
# проверка плана на обыкновенность
if len(I0) == 0 or linalg.matrix_rank(matrix) != len(I0):
a0 = Symbol("a0", nonnegative=True)
print(notUsualPlanLabel)
else:
a0 = 1.0
print(usualPlanLabel)
df = [f.diff(xi) for xi in x]
dg = []
for gi in g:
dg.append([gi.diff(xi) for xi in x])
# ищем решение уравнения из формулы
lambdas, dg_ = lambda_solution(plan_, df, dg, a0, a, g_plan)
if lambdas:
if type(lambdas) == list:
lambdas = lambdas[0]
if (array(lambdas.values()) == 0.0).all():
print(necessaryNotPassedLabel)
return
print(necessaryPassedLabel)
else:
print(necessaryNotPassedLabel)
return
I0_plus = [ind for ind in I0 if lambdas[a[ind]] > 0.0] # indexes where lambda greater than zero
# найдём К
eqs = []
for i in I0_plus:
eq = 0
for li, dgi in zip(l, dg_[i]):
eq += li * dgi
eqs.append(eq)
K = solve(eqs)
# проверим К если множество
if not K:
print(sufficientPassedLabel) #
else:
ddf = []
for xi in x:
ddf.append([ddfi.diff(xi) for ddfi in df])
ddf = Matrix(ddf)
ll = Matrix(l)
if Matrix(ddf.dot(ll.T)).dot(ll).subs(K) > 0:
print(sufficientPassedLabel)
else:
print(sufficientNotPassedLabel)