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


Python Matrix.nullspace方法代码示例

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


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

示例1: test_nullspace

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import nullspace [as 别名]
def test_nullspace():
    # first test reduced row-ech form
    R = Rational

    M = Matrix([[5,7,2,1],
               [1,6,2,-1]])
    out, tmp = M.rref()
    assert out == Matrix([[1,0,-R(2)/23,R(13)/23],
                              [0,1,R(8)/23, R(-6)/23]])

    M = Matrix([[-5,-1, 4,-3,-1],
                [ 1,-1,-1, 1, 0],
                [-1, 0, 0, 0, 0],
                [ 4, 1,-4, 3, 1],
                [-2, 0, 2,-2,-1]])
    assert M*M.nullspace()[0] == Matrix(5,1,[0]*5)

    M = Matrix([[1,3,0,2,6,3,1],
                [-2,-6,0,-2,-8,3,1],
                [3,9,0,0,6,6,2],
                [-1,-3,0,1,0,9,3]])
    out, tmp = M.rref()
    assert out == Matrix([[1,3,0,0,2,0,0],
                               [0,0,0,1,2,0,0],
                               [0,0,0,0,0,1,R(1)/3],
                               [0,0,0,0,0,0,0]])

    # now check the vectors
    basis = M.nullspace()
    assert basis[0] == Matrix([-3,1,0,0,0,0,0])
    assert basis[1] == Matrix([0,0,1,0,0,0,0])
    assert basis[2] == Matrix([-2,0,0,-2,1,0,0])
    assert basis[3] == Matrix([0,0,0,0,0,R(-1)/3, 1])
开发者ID:cran,项目名称:rSymPy,代码行数:35,代码来源:test_matrices.py

示例2: getInvariants

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import nullspace [as 别名]
def getInvariants(qds, verbosity=1, print_stream=sys.stdout):
    n_inter = len(qds.interactions)
    n_types = qds.ntypes

    int_matrix = np.zeros([n_inter, n_types], dtype=int)
    for (idx, (i, j, k, l)) in enumerate(qds.interactions):
        int_matrix[idx, i] += 1
        int_matrix[idx, j] += 1
        int_matrix[idx, k] -= 1
        int_matrix[idx, l] -= 1

    IM = Matrix(int_matrix)
    invs = np.array(IM.nullspace(), dtype=float)

    if verbosity > 0:
        print("The invariants for the system are the following: \n\n",
              file=print_stream)
        for i in range(invs.shape[0]):
            inv_str = ""
            for j in range(invs.shape[1]):
                if invs[i, j] != 0:
                    if inv_str != "":
                        inv_str += " + %.3f x p_%d" % (invs[i, j], j)
                    else:
                        inv_str += "%.3f x p_%d" % (invs[i, j], j)
            print(inv_str + "\n", file=print_stream)

    return invs
开发者ID:vkanade,项目名称:quadratic,代码行数:30,代码来源:qds_helper.py

示例3: find_symbolic_dependent_columns

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import nullspace [as 别名]
def find_symbolic_dependent_columns(x):
    """
    Find linearly dependent columns using symbolic calculations.
    :param x: The input numpy array
    :return: The linear combination matrix (Null Space of MAtrix).
    """
    x = Matrix(x)
    return(x.nullspace())
开发者ID:r2rahul,项目名称:dimensionreduction,代码行数:10,代码来源:driver_linear_combination_calculator.py

示例4: compute_steadystate

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import nullspace [as 别名]
 def compute_steadystate(self, nnc=2): #nnc is the position of the constant in the state vector
     """ Find non-stochastic steady-state of the economy """
     zx = Matrix(np.eye(self.A0.shape[0])-self.A0)
     self.zz = zx.nullspace()
     self.zz = array(self.zz)
     self.zz = self.zz.T
     self.zz = zz = self.zz/self.zz[nnc] 
     self.css = self.Sc.dot(self.zz).astype(float)
     self.sss = self.Ss.dot(self.zz).astype(float)
     self.iss = self.Si.dot(self.zz).astype(float)
     self.dss = self.Sd.dot(self.zz).astype(float)
     self.bss = self.Sb.dot(self.zz).astype(float)
     self.kss = self.Sk.dot(self.zz).astype(float)
     self.hss = self.Sh.dot(self.zz).astype(float)
开发者ID:sebgraves,项目名称:RMDLE,代码行数:16,代码来源:DynLinEcon.py

示例5: test_sparse_matrix

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import nullspace [as 别名]

#.........这里部分代码省略.........

    # test_inverse
    A = eye(4)
    assert A.inv() == eye(4)
    assert A.inv("LU") == eye(4)
    assert A.inv("ADJ") == eye(4)
    A = SMatrix([[2,3,5],
                [3,6,2],
                [8,3,6]])
    Ainv = A.inv()
    assert A*Ainv == eye(3)
    assert A.inv("LU") == Ainv
    assert A.inv("ADJ") == Ainv

    # test_cross
    v1 = Matrix(1,3,[1,2,3])
    v2 = Matrix(1,3,[3,4,5])
    assert v1.cross(v2) == Matrix(1,3,[-2,4,-2])
    assert v1.norm(v1) == 14

    # test_cofactor
    assert eye(3) == eye(3).cofactorMatrix()
    test = SMatrix([[1,3,2],[2,6,3],[2,3,6]])
    assert test.cofactorMatrix() == SMatrix([[27,-6,-6],[-12,2,3],[-3,1,0]])
    test = SMatrix([[1,2,3],[4,5,6],[7,8,9]])
    assert test.cofactorMatrix() == SMatrix([[-3,6,-3],[6,-12,6],[-3,6,-3]])

    # test_jacobian
    x = Symbol('x')
    y = Symbol('y')
    L = SMatrix(1,2,[x**2*y, 2*y**2 + x*y])
    syms = [x,y]
    assert L.jacobian(syms) == Matrix([[2*x*y, x**2],[y, 4*y+x]])

    L = SMatrix(1,2,[x, x**2*y**3])
    assert L.jacobian(syms) == SMatrix([[1, 0], [2*x*y**3, x**2*3*y**2]])

    # test_QR
    A = Matrix([[1,2],[2,3]])
    Q, S = A.QRdecomposition()
    R = Rational
    assert Q == Matrix([[5**R(-1,2), (R(2)/5)*(R(1)/5)**R(-1,2)], [2*5**R(-1,2), (-R(1)/5)*(R(1)/5)**R(-1,2)]])
    assert S == Matrix([[5**R(1,2), 8*5**R(-1,2)], [0, (R(1)/5)**R(1,2)]])
    assert Q*S == A
    assert Q.T * Q == eye(2)

    # test nullspace
    # first test reduced row-ech form
    R = Rational

    M = Matrix([[5,7,2,1],
               [1,6,2,-1]])
    out, tmp = M.rref()
    assert out == Matrix([[1,0,-R(2)/23,R(13)/23],
                              [0,1,R(8)/23, R(-6)/23]])

    M = Matrix([[1,3,0,2,6,3,1],
                [-2,-6,0,-2,-8,3,1],
                [3,9,0,0,6,6,2],
                [-1,-3,0,1,0,9,3]])
    out, tmp = M.rref()
    assert out == Matrix([[1,3,0,0,2,0,0],
                               [0,0,0,1,2,0,0],
                               [0,0,0,0,0,1,R(1)/3],
                               [0,0,0,0,0,0,0]])
    # now check the vectors
    basis = M.nullspace()
    assert basis[0] == Matrix([[-3,1,0,0,0,0,0]])
    assert basis[1] == Matrix([[0,0,1,0,0,0,0]])
    assert basis[2] == Matrix([[-2,0,0,-2,1,0,0]])
    assert basis[3] == Matrix([[0,0,0,0,0,R(-1)/3, 1]])


    # test eigen
    x = Symbol('x')
    y = Symbol('y')
    eye3 = eye(3)
    assert eye3.charpoly(x) == (1-x)**3
    assert eye3.charpoly(y) == (1-y)**3
    # test values
    M = Matrix([(0,1,-1),
                (1,1,0),
                (-1,0,1) ])
    vals = M.eigenvals()
    vals.sort()
    assert vals == [-1, 1, 2]

    R = Rational
    M = Matrix([ [1,0,0],
                 [0,1,0],
                 [0,0,1]])
    assert M.eigenvects() == [[1, 3, [Matrix(1,3,[1,0,0]), Matrix(1,3,[0,1,0]), Matrix(1,3,[0,0,1])]]]
    M = Matrix([ [5,0,2],
                 [3,2,0],
                 [0,0,1]])
    assert M.eigenvects() == [[1, 1, [Matrix(1,3,[R(-1)/2,R(3)/2,1])]],
                              [2, 1, [Matrix(1,3,[0,1,0])]],
                              [5, 1, [Matrix(1,3,[1,1,0])]]]

    assert M.zeros((3, 5)) == SMatrix(3, 5, {})
开发者ID:Lucaweihs,项目名称:sympy,代码行数:104,代码来源:test_matrices.py


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