本文整理汇总了Python中matrix.Matrix.multiplyMatrix方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.multiplyMatrix方法的具体用法?Python Matrix.multiplyMatrix怎么用?Python Matrix.multiplyMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.multiplyMatrix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rotationMethod
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import multiplyMatrix [as 别名]
def rotationMethod(m,A,a,epsilon,p):
#print("Start Rotation.")
VECTOR = 1
X = Matrix(m,VECTOR)
oldA = Matrix(m,m)
r = Matrix(m,VECTOR)
iterationNumber = 0
condition = True
#print("Entering while.")
while condition:
#print("OldA copy.")
oldA = copy.deepcopy(A)
#print("0")
r = copy.deepcopy(a.substractMatrix(A.matrixMultiplication(X,a)))
#print("1")
(xpq,p,q) = getMax(A.lowerTriangularMatrix())
#print("2")
theta = 0
if A.lowerTriangularMatrix().at(p,p) == A.lowerTriangularMatrix().at(q,q):
#print("3")
theta = math.pi/4
else:
#print("4")
theta = ( 2 * xpq )/(A.upperTriangularMatrix().at(p,p) - A.upperTriangularMatrix().at(q,q) + (10**(-5)))
#print("Determined theta.")
c = math.cos(theta)
s = math.sin(theta)
#print("5")
T = Matrix(m,m)
for i in range(0,T.numberOfColumns):
T.insert(i,i,1)
T.insert(p,p,c)
T.insert(p,q,s)
T.insert(q,p,-s)
T.insert(q,q,c)
#print("Determined T.")
A = copy.deepcopy((T.transpose()).multiplyMatrix(oldA.multiplyMatrix(T)))
#condition = not r.isAlmostZero()
if iterationNumber%100 == 0:
print("-----")
print("Situation at iteration:",iterationNumber)
print("Condition:",condition)
print("A matrix:")
A.display()
print("X matrix:")
X.display()
print("-----")
X = copy.deepcopy(oldA)
iterationNumber += 1
condition = iterationNumber > 10**(15)
#condition = checkX(X)
print("===== Rotation Method =====")
print("X:")
X.display()
print("A:")
A.display()
#print("Test:")
#r.display()
print("====================")
示例2: rotationMethod
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import multiplyMatrix [as 别名]
def rotationMethod(m,A,a,epsilon,p):
VECTOR = 1
X = Matrix(m,VECTOR)
oldA = Matrix(m,m)
r = Matrix(m,VECTOR)
iterationNumber = 0
condition = True
while condition:
oldA = copy.deepcopy(A)
r = copy.deepcopy(a.substractMatrix(A.matrixMultiplication(X,a)))
(xpq,p,q) = getMax(A.lowerTriangularMatrix())
theta = 0
if A.lowerTriangularMatrix().at(p,p) == A.lowerTriangularMatrix().at(q,q):
theta = math.pi/4
else:
theta = (1/2)*math.arct(( 2 * xpq )/(A.upperTriangularMatrix().at(p,p) - A.upperTriangularMatrix().at(q,q)))
c = math.cos(theta)
s = math.sin(theta)
T = Matrix(m,m)
for i in range(0,T.numberOfColumns):
T.insert(i,i,1)
T.insert(p,p,c)
T.insert(p,q,s)
T.insert(q,p,-s)
T.insert(q,q,c)
A = copy.deepcopy((T.transpose()).multiplyMatrix(oldA.multiplyMatrix(T)))
'''
if iterationNumber%100 == 0:
print("-----")
print("Situation at iteration:",iterationNumber)
print("Condition:",condition)
print("A matrix:")
A.display()
print("X matrix:")
X.display()
print("-----")
'''
X = copy.deepcopy(oldA)
iterationNumber += 1
condition = (iterationNumber < ITERATIONS)
print("===== Rotation Method =====")
print("X:")
X.display()
print("A:")
A.display()
print("Test:")
r.display()
print("====================")