prodop.m

来自「The goal of SPID is to provide the user 」· M 代码 · 共 67 行

M
67
字号
function output=prodop(spin_num,xyz,spin);
    
    %calculate spin operators
    ident=eye(spin_num);

    %product operators
    halfunity=sparse([1/2 0 ; 0 1/2]);
    Ix=sparse([0 1/2 ; 1/2 0]);
    Iy=sparse([0 -1/2*i ; 1/2*i 0]);
    Iz=sparse([1/2 0 ; 0 -1/2]);
  
    if xyz=='x'
        for n=1:spin_num
            if n==1
                if ident(n,spin)==0
                    temp=halfunity;
                else
                    temp=Ix; 
                end
            else
                if ident(n,spin)==0
                    temp=kron(temp,halfunity);
                else
                    temp=kron(temp,Ix); 
                end
            end
        end
    end
    
    if xyz=='y'
        for n=1:spin_num
            if n==1
                if ident(n,spin)==0
                    temp=halfunity;
                else
                    temp=Iy; 
                end
            else
                if ident(n,spin)==0
                    temp=kron(temp,halfunity);
                else
                    temp=kron(temp,Iy); 
                end
            end
        end
    end

    if xyz=='z'
        for n=1:spin_num
            if n==1
                if ident(n,spin)==0
                    temp=halfunity;
                else
                    temp=Iz; 
                end
            else
                if ident(n,spin)==0
                    temp=kron(temp,halfunity);
                else
                    temp=kron(temp,Iz); 
                end
            end
        end
    end
    output=temp;
    output=output*2^(spin_num-1);
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?