本文整理汇总了Python中sympy.matrices.Matrix.gauss_jordan_solve方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.gauss_jordan_solve方法的具体用法?Python Matrix.gauss_jordan_solve怎么用?Python Matrix.gauss_jordan_solve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.matrices.Matrix
的用法示例。
在下文中一共展示了Matrix.gauss_jordan_solve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __add__
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import gauss_jordan_solve [as 别名]
def __add__(self, other):
deg1 = self.annihilator.order
deg2 = other.annihilator.order
dim = max(deg1, deg2)
rowsself = [self.annihilator]
rowsother = [other.annihilator]
gen = self.annihilator.parent.derivative_operator
# constructing annihilators up to order dim
for i in range(dim - deg1):
diff1 = (gen * rowsself[-1])
rowsself.append(diff1)
for i in range(dim - deg2):
diff2 = (gen * rowsother[-1])
rowsother.append(diff2)
row = rowsself + rowsother
# constructing the matrix of the ansatz
r = []
for expr in row:
p = []
for i in range(dim + 1):
if i >= len(expr.listofpoly):
p.append(0)
else:
if isinstance(expr.listofpoly[i], self.annihilator.parent.base.dtype):
ring_to_expr = self.annihilator.parent.base.to_sympy(
expr.listofpoly[i])
p.append(ring_to_expr)
else:
p.append(expr.listofpoly[i])
r.append(p)
r = Matrix(r).transpose()
homosys = [[0 for q in range(dim + 1)]]
homosys = Matrix(homosys).transpose()
# solving the linear system using gauss jordan solver
solcomp = r.gauss_jordan_solve(homosys)
sol = (r).gauss_jordan_solve(homosys)[0]
# if a solution is not obtained then increasing the order by 1 in each
# iteration
while sol.is_zero:
dim += 1
diff1 = (gen * rowsself[-1])
rowsself.append(diff1)
diff2 = (gen * rowsother[-1])
rowsother.append(diff2)
row = rowsself + rowsother
r = []
for expr in row:
p = []
for i in range(dim + 1):
if i >= len(expr.listofpoly):
p.append(0)
else:
if isinstance(expr.listofpoly[i], self.annihilator.parent.base.dtype):
ring_to_expr = self.annihilator.parent.base.to_sympy(
expr.listofpoly[i])
p.append(ring_to_expr)
else:
p.append(expr.listofpoly[i])
r.append(p)
r = Matrix(r).transpose()
homosys = [[0 for q in range(dim + 1)]]
homosys = Matrix(homosys).transpose()
solcomp = r.gauss_jordan_solve(homosys)
sol = r.gauss_jordan_solve(homosys)[0]
# removing the symbol if any from the solution
if sol.is_symbolic():
sol = solcomp[0] / solcomp[1]
# taking only the coefficients needed to multiply with `self`
# can be also be done the other way by taking R.H.S and multiply with
# `other`
sol = sol[:dim + 1 - deg1]
sol = _normalize(sol, self.x)
# construct operator from list of coefficients
sol1 = DifferentialOperator(
sol, self.annihilator.parent)
# annihilator of the solution
sol = sol1 * (self.annihilator)
#.........这里部分代码省略.........