矩阵指数为两个相似的矩阵

时间:2017-05-01 06:06:23

标签: python scipy

我构建了两个矩阵。对于一个我计算矩阵指数,但对于另一个我不能。它们具有相似的结构并具有相同的结构和尺寸。我真的不知道为什么一个人可以工作,但另一个人不能。我把我的代码放在下面。

import numpy as np
import math as math
from scipy.sparse import csc_matrix
from scipy.sparse.linalg import *

sigmax = [[0, 1], [1, 0]]
sigmay = [[0, -1j], [1j, 0]]
sigmaz = [[1, 0], [0, -1]]
sigmaxx = np.kron(sigmax,sigmax)
sigmayy = np.kron(sigmay,sigmay)
sigmazz = np.kron(sigmaz,sigmaz)
sigmaxxyy = np.mat(sigmaxx) + np.mat(sigmayy)
N = 6

Hxxyy = 0
for i in range (0,N-2+1):
    Hxxyy = np.mat(Hxxyy) + np.mat(np.kron(np.kron(np.identity(2**i),2*np.mat(sigmaxxyy)),np.identity(2**(N-i-2)) ))
Hxxyy = np.mat(Hxxyy) + np.mat(np.kron(np.kron(2*np.mat(sigmax),np.identity(2**(N-2))),sigmax))+np.mat(np.kron(np.kron(2*np.mat(sigmay),np.identity(2**(N-2))),sigmay))   
print(expm(Hxxyy))

Hhi = 0
for j in range (0,N-1+1):
    Hhi = np.mat(Hhi) + np.mat(np.kron( np.kron(np.identity(2**j),3*np.mat(sigmaz)),np.identity(2**(N-1-j))) )
print(expm(Hhi))

错误消息是:

Traceback (most recent call last):
  File "new test.py", line 20, in <module>
    print(expm(Hhi))
  File "/Users/sherlock/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/scipy/sparse/linalg/matfuncs.py", line 582, in expm
    return _expm(A, use_exact_onenorm='auto')
  File "/Users/sherlock/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/scipy/sparse/linalg/matfuncs.py", line 637, in _expm
    X = _fragment_2_1(X, h.A, s)
  File "/Users/sherlock/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/scipy/sparse/linalg/matfuncs.py", line 755, in _fragment_2_1
    X[k, k] = exp_diag[k]
ValueError: setting an array element with a sequence.

0 个答案:

没有答案