24小时热门版块排行榜    

查看: 726  |  回复: 3

cathy_ac

铁虫 (初入文坛)

[求助] python写的一个绝对对角化的一个程序跑出来能量是复数 已有1人参与

用python写了一个一维相互作用0 disorder的自旋为1/2的费米子系统,basis用Fock空间来表示,可是算出来的能量总是为复数,而且,博后要我画transition energy和相互作用U的曲线,在L个晶格,总数为L个电子的时候,不同晶格数的曲线是相互交叉的,不管怎么样我都得不到这样的答案,这个问题已经困扰我一个月了。大神们能不能帮我看一下
回复此楼

» 猜你喜欢

保存
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

KalaShayminS

铁杆木虫 (著名写手)

这没有程序想看也看不了啊
2楼2015-03-17 00:21:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cathy_ac

铁虫 (初入文坛)

引用回帖:
2楼: Originally posted by KalaShayminS at 2015-03-17 00:21:45
这没有程序想看也看不了啊

def dim(L, Np, Nd):
    # number of basis states,Np denotes the number of spin up fermions and
    # Nd denote the spin-down fermions
    return ((math.factorial(L) * math.factorial(L)) /
            (math.factorial(Nd) * math.factorial(Np) *
             math.factorial(L - Np) * math.factorial(L - Nd)))


def dim_compact(L, N):
    return (math.factorial(L)) / (math.factorial(N) * math.factorial(L - N))


def matglue(a, b):
    r = []
    for i in a:
        for j in b:
            r.append(concatenate([i, j]))

    u = np.matrix(r)
    return u


def NinL(L, N):
    # Ns=dim(L,N)
    Ns = dim_compact(L, N)

    # array that stores all basis states in terms of lattice occupation
    # numbers (list of occupation number states):
    nl = zeros((Ns, L), int)
    # first basis state with all particles ordered to the left:
    for l in range(N):
        nl[0, l] = 1
    for a in range(Ns-1):
        if nl[a, L-1] != 1:
            for j in reversed(range(L-1)):
                if nl[a, j] == 1 and nl[a, j + 1] == 0:
                    for i in range(j):
                        nl[a + 1, i] = nl[a, i]
                    nl[a+1, j] = 0
                    nl[a+1, j+1] = 1
                    break
        else:
            for j in reversed(range(L-1)):
                if nl[a, j] == 1 and nl[a, j+1] == 0:
                    for i in range(j):
                        nl[a+1, i] = nl[a, i]
                    nl[a+1, j] = 0
                    nl[a+1, j+1] = 1
                    c = 0
                    for i in range(j+2, L):
                        c += nl[a, i]
                    for i in range(j+2, j+2+c):
                        nl[a+1, i] = 1
                    break
    return nl


def basis(L, Nd, Np):
    Mp = NinL(L, Np)
    Md = NinL(L, Nd)
    nl = matglue(Mp, Md)
    return nl


# single-particle Hamiltonian definition:
def H1(V, b, phi, j):
    return V * cos(2 * pi * b * j + phi)


# doublon number of a configuration comprised of spinless-half fermions
def doub(nl,L):
    conf = 0
    nl = nl.tolist()[0]
    # check wether a site is occupied by a doublon
    for i in range(L):
        if nl == 1 and nl[i+L] == 1:
            conf += 1
    return conf

# adding hopping element in the Hamiltonian
def new_hopmat(L, Nd, Np):
    nl = basis(L, Nd, Np)
    Ns = dim(L, Np, Nd)
    H = zeros((Ns, Ns))
    L2 = 2 * L
    #N = 0
    lookup = {}
    for a1 in range(Ns):
        m = nl[a1]
        l = m.tolist()[0]
        #print l
        k = ''.join(str(i) for i in l)
        lookup.setdefault(k,  a1)
    #print lookup

    for a1 in range(Ns):
        for i in range(L2 - 1):
            if nl[a1, i] != nl[a1, i + 1]:
                tmp = [] + nl[a1].tolist()[0]
                tmp = 1 - nl[a1, i]
                tmp[i + 1] = 1 - nl[a1, i + 1]
                k = ''.join(str(j) for j in tmp)
                if lookup.has_key(k):
                    a2 = lookup[k]
                    if nl[a1, i] == 1:
                        H[a1, a2] += -1.
                    else:
                        H[a1,a2] += 1.
                    #N += -1.
    #print N                               
                   #H[a2, a1] += -1.
    return H, Ns, nl
               
# many-body Hamiltonian definition:
def Hmany(L, Nd, Np, V, b, phi, U):
    #H, Ns, nl = Hopmat(L, Nd, Np)
    H, Ns, nl = new_hopmat(L, Nd, Np)

    for a in range(Ns):
        H[a, a] += U * doub(nl[a],L)
        #print(H[a,a], a)
        # sum over all particle and spin of single particle potential
        #for j in range(2 * L):
            #H[a, a] += H1(V, b, phi, j) * nl[a, j]
    return H
保存
3楼2015-03-17 03:26:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

KalaShayminS

铁杆木虫 (著名写手)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
cathy_ac: 金币+15, ★★★很有帮助 2015-03-30 19:27:45
new_hopmat里面H[a1,a2]的数值按我的理解应该和正负号没有关系吧?
这是个厄米矩阵,i,j和j,i是共轭关系,不是相反数的关系.
4楼2015-03-17 17:02:53
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 cathy_ac 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 求材料,环境专业调剂 +3 18567500178 2026-03-18 3/150 2026-03-23 23:50 by 热情沙漠
[考研] 085600材料与化工调剂 +7 A-哆啦Z梦 2026-03-23 12/600 2026-03-23 23:16 by 星空星月
[考研] 一志愿中南化学(0703)总分337求调剂 +9 niko- 2026-03-19 10/500 2026-03-22 16:08 by ColorlessPI
[考研] 324求调剂 +6 lucky呀呀呀鸭 2026-03-20 6/300 2026-03-22 16:01 by ColorlessPI
[考研] 0856材料专硕353求调剂 +4 NIFFFfff 2026-03-20 4/200 2026-03-22 09:49 by 2026paper
[考研] 化学调剂 +5 yzysaa 2026-03-21 5/250 2026-03-21 22:12 by peike
[考研] 297求调剂 +3 喜欢还是不甘心 2026-03-20 3/150 2026-03-21 18:33 by 学员8dgXkO
[考研] 278求调剂 +9 烟火先于春 2026-03-17 9/450 2026-03-21 17:47 by 学员8dgXkO
[考研] 材料学学硕080502 337求调剂-一志愿华中科技大学 +4 顺顺顺mr 2026-03-18 5/250 2026-03-21 10:22 by luoyongfeng
[考研] 307求调剂 +3 wyyyqx 2026-03-17 3/150 2026-03-21 03:20 by JourneyLucky
[考研] 085700资源与环境308求调剂 +12 墨墨漠 2026-03-18 13/650 2026-03-21 01:42 by JourneyLucky
[考研] 华东师范大学-071000生物学-293分-求调剂 +3 研究生何瑶明 2026-03-18 3/150 2026-03-21 01:30 by JourneyLucky
[考研] 一志愿西南交大,求调剂 +5 材化逐梦人 2026-03-18 5/250 2026-03-21 00:26 by JourneyLucky
[考研] 274求调剂 +10 S.H1 2026-03-18 10/500 2026-03-20 23:51 by JourneyLucky
[考研] 329求调剂 +9 想上学吖吖 2026-03-19 9/450 2026-03-20 22:01 by luoyongfeng
[考研] 295复试调剂 +8 简木ChuFront 2026-03-19 8/400 2026-03-20 20:44 by zhukairuo
[考研] 0817 化学工程 299分求调剂 有科研经历 有二区文章 +22 rare12345 2026-03-18 22/1100 2026-03-20 20:39 by zhukairuo
[考研] 材料学求调剂 +4 Stella_Yao 2026-03-20 4/200 2026-03-20 20:28 by ms629
[考研] 0856调剂,是学校就去 +8 sllhht 2026-03-19 9/450 2026-03-20 14:25 by 无懈可击111
[考研] 考研求调剂 +3 橘颂. 2026-03-17 4/200 2026-03-17 21:43 by 有只狸奴
信息提示
请填处理意见