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


Python Matrix.eigenvals方法代码示例

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


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

示例1: test_eigen

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import eigenvals [as 别名]
def test_eigen():
    x,y = symbols('xy')

    R = Rational

    assert eye(3).charpoly(x) == Poly((x-1)**3, x)
    assert eye(3).charpoly(y) == Poly((y-1)**3, y)

    M = Matrix([[1,0,0],
                [0,1,0],
                [0,0,1]])

    assert M.eigenvals() == {S.One: 3}

    assert canonicalize(M.eigenvects()) == canonicalize(
        [(1, 3, [Matrix([1,0,0]),
                 Matrix([0,1,0]),
                 Matrix([0,0,1])])])

    M = Matrix([[0,1,1],
                [1,0,0],
                [1,1,1]])

    assert M.eigenvals() == {2*S.One: 1, -S.One: 1, S.Zero: 1}

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

    eps = Symbol('eps',real=True)

    M = Matrix([[abs(eps), I*eps    ],
               [-I*eps,   abs(eps) ]])

    assert canonicalize(M.eigenvects()) == canonicalize(
        [( 2*abs(eps), 1, [ Matrix([[I*eps/abs(eps)],[1]]) ] ),
         ( 0, 1, [Matrix([[-I*eps/abs(eps)],[1]])]) ])
开发者ID:cran,项目名称:rSymPy,代码行数:40,代码来源:test_matrices.py

示例2: setDefaultLearningRate

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import eigenvals [as 别名]
    def setDefaultLearningRate(self):
        from sympy import Matrix
        num=len(self.net.input_data)
        sum=Matrix([[0 for column in range(len(self.net.input_data[0]))]for row in range(len(self.net.input_data[0]))])
        for elem in self.net.input_data:
            mat=Matrix([elem])
            mat=mat.transpose()*mat/num
            sum=sum+mat
        eigenvalue=sum.eigenvals()
        max=0
    # print 'sum'
    #print sum
    # print eigenvalue
        for keys in eigenvalue:
            if keys>max:
                max=keys
        self.learning_rate=1/max
    
    

        
开发者ID:shd101wyy,项目名称:PyNeuron,代码行数:19,代码来源:LMSTrainer.py

示例3: test_sparse_matrix

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

示例4: test_eigen

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import eigenvals [as 别名]
def test_eigen():
    x,y = symbols('xy')

    R = Rational

    assert eye(3).charpoly(x) == Poly((x-1)**3, x)
    assert eye(3).charpoly(y) == Poly((y-1)**3, y)

    M = Matrix([[1,0,0],
                [0,1,0],
                [0,0,1]])

    assert M.eigenvals() == {S.One: 3}

    assert canonicalize(M.eigenvects()) == canonicalize(
        [(1, 3, [Matrix([1,0,0]),
                 Matrix([0,1,0]),
                 Matrix([0,0,1])])])

    M = Matrix([[0,1,1],
                [1,0,0],
                [1,1,1]])

    assert M.eigenvals() == {2*S.One: 1, -S.One: 1, S.Zero: 1}

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

    M = Matrix([ [1, -1],
                 [1,  3]])
    assert canonicalize(M.eigenvects()) == canonicalize(
        [[2, 2, [Matrix(1,2,[-1,1])]]])

    M = Matrix([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ])
    a=R(15,2)
    b=3*33**R(1,2)
    c=R(13,2)
    d=(R(33,8) + 3*b/8)
    e=(R(33,8) - 3*b/8)
    def NS(e, n):
        return str(N(e, n))
    r = [
        (a - b/2, 1, [Matrix([(12 + 24/(c - b/2))/((c - b/2)*e) + 3/(c - b/2),
                              (6 + 12/(c - b/2))/e,1])]),
        (      0, 1, [Matrix([1,-2,1])]),
        (a + b/2, 1, [Matrix([(12 + 24/(c + b/2))/((c + b/2)*d) + 3/(c + b/2),
                              (6 + 12/(c + b/2))/d,1])]),
        ]
    r1 = [(NS(r[i][0],2),NS(r[i][1],2),[NS(j,2) for j in r[i][2][0]]) for i in range(len(r))]
    r = M.eigenvects()
    r2=[(NS(r[i][0],2),NS(r[i][1],2),[NS(j,2) for j in r[i][2][0]]) for i in range(len(r))]
    assert sorted(r1) == sorted(r2)

    eps = Symbol('eps',real=True)

    M = Matrix([[abs(eps), I*eps    ],
               [-I*eps,   abs(eps) ]])

    assert canonicalize(M.eigenvects()) == canonicalize(
        [( 2*abs(eps), 1, [ Matrix([[I*eps/abs(eps)],[1]]) ] ),
         ( 0, 1, [Matrix([[-I*eps/abs(eps)],[1]])]) ])
开发者ID:Lucaweihs,项目名称:sympy,代码行数:65,代码来源:test_matrices.py


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