当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.append方法代码示例

本文整理汇总了Python中sympy.matrices.Matrix.append方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.append方法的具体用法?Python Matrix.append怎么用?Python Matrix.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.matrices.Matrix的用法示例。


在下文中一共展示了Matrix.append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __add__

# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import append [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)

#.........这里部分代码省略.........
开发者ID:Asnelchristian,项目名称:sympy,代码行数:103,代码来源:holonomic.py


注:本文中的sympy.matrices.Matrix.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。