Skip to main content
edited title
Link
user64494
  • 29.1k
  • 4
  • 29
  • 56

efficient Efficient ways to generate a matrix from multiplying two elements of some matrix

better format
Source Link
AsukaMinato
  • 10.4k
  • 1
  • 17
  • 44

I am working on the single particle entanglement entropy and in the process I have something like

Table[Sum[states[[eindexTable[
    Sum[
        states[[eindex, spaceindex]]*states[[eindexspaceindex]] * states[[eindex, spaceindex2]], 
        {eindex,1, Na/2}(*trace over lower-half filling*)
    ], 
    {spaceindex, 1, Nb}, 
    {spaceindex2, 1, Nb}(*some subsystem*) 
]

where states is a Na by Na square matrix, from diagonalizing some other matrix. 1<Nb<Na is some sub-system. The matrix I am trying to construct is essentially $C_{i,j}=Tr[states[k,i]*states[k,j]]$ traced over the first index.

The above code gets the job done but I wonder if there are more efficient ways.

Also, I keep getting myself into this situation where I need to generate a matrix efficiently via similar constructions, for example, projection matrices. I would also like to know some general ways to directly translate the equations into efficient code.

I am working on the single particle entanglement entropy and in the process I have something like

Table[Sum[states[[eindex, spaceindex]]*states[[eindex, spaceindex2]], {eindex,1, Na/2}(*trace over lower-half filling*)], {spaceindex, 1, Nb}, {spaceindex2, 1, Nb}(*some subsystem*)]

where states is a Na by Na square matrix, from diagonalizing some other matrix. 1<Nb<Na is some sub-system. The matrix I am trying to construct is essentially $C_{i,j}=Tr[states[k,i]*states[k,j]]$ traced over the first index.

The above code gets the job done but I wonder if there are more efficient ways.

Also, I keep getting myself into this situation where I need to generate a matrix efficiently via similar constructions, for example, projection matrices. I would also like to know some general ways to directly translate the equations into efficient code.

I am working on the single particle entanglement entropy and in the process I have something like

Table[
    Sum[
        states[[eindex, spaceindex]] * states[[eindex, spaceindex2]], 
        {eindex,1, Na/2}(*trace over lower-half filling*)
    ], 
    {spaceindex, 1, Nb}, 
    {spaceindex2, 1, Nb}(*some subsystem*) 
]

where states is a Na by Na square matrix, from diagonalizing some other matrix. 1<Nb<Na is some sub-system. The matrix I am trying to construct is essentially $C_{i,j}=Tr[states[k,i]*states[k,j]]$ traced over the first index.

The above code gets the job done but I wonder if there are more efficient ways.

Also, I keep getting myself into this situation where I need to generate a matrix efficiently via similar constructions, for example, projection matrices. I would also like to know some general ways to directly translate the equations into efficient code.

Source Link
wooohooo
  • 319
  • 1
  • 8

efficient ways to generate a matrix from multiplying two elements of some matrix

I am working on the single particle entanglement entropy and in the process I have something like

Table[Sum[states[[eindex, spaceindex]]*states[[eindex, spaceindex2]], {eindex,1, Na/2}(*trace over lower-half filling*)], {spaceindex, 1, Nb}, {spaceindex2, 1, Nb}(*some subsystem*)]

where states is a Na by Na square matrix, from diagonalizing some other matrix. 1<Nb<Na is some sub-system. The matrix I am trying to construct is essentially $C_{i,j}=Tr[states[k,i]*states[k,j]]$ traced over the first index.

The above code gets the job done but I wonder if there are more efficient ways.

Also, I keep getting myself into this situation where I need to generate a matrix efficiently via similar constructions, for example, projection matrices. I would also like to know some general ways to directly translate the equations into efficient code.