no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


Previous revision
Next revision
documentation:language_reference:functions:braket [2022/09/30 17:50] Maurits W. Haverkort
Line 1: Line 1:
 +====== Braket ======
 +
 +###
 +//Braket(psi1, O, psi2)// calculates the expectation value or matrix element $\left\langle \psi_1 \mid O \mid \psi_2 \right\rangle$. In Quanty //Braket(psi1, O, psi2)// is the same as // psi1 * O * psi2//. The difference is that the function //Braket// can be faster. //Braket// can work on lists of functions and then returns a matrix or vector with all possible expectation values
 +###
 +
 +===== Input =====
 +
 +  * psi1 or psiList1 : Wavefunction or list of Wavefunctions
 +  * O                : Operator
 +  * psi2 or psiList2 : Wavefunction or list of Wavefunctions
 +
 +===== Output =====
 +
 +  * real or complex number, or a list of these or a matrix of these
 +
 +===== Example =====
 +
 +###
 +The example calculates the expectation values of a few states
 +###
 +
 +==== Input ====
 +<code Quanty Example.Quanty>
 +NF=2
 +NB=0
 +IndexDn={0}
 +IndexUp={1}
 +
 +psi0=NewWavefunction(NF,NB,{{"10",1}})
 +psi1=NewWavefunction(NF,NB,{{"01",1}})
 +
 +OppSx   = NewOperator("Sx"   ,NF,IndexUp,IndexDn)
 +OppSy   = NewOperator("Sy"   ,NF,IndexUp,IndexDn)
 +OppSz   = NewOperator("Sz"   ,NF,IndexUp,IndexDn)
 +
 +print("The expectation value of a single state")
 +print(Braket(psi0,OppSz,psi0))
 +
 +print("The expectation value of a single state with two other states")
 +print(Braket(psi0,OppSx,{psi0,psi1}))
 +
 +-- note that I made one list of length 3, the other of length 2 so that the order is clear
 +print("The expectation value of a two states with two other states")
 +print(Braket({psi0,psi1},OppSy,{psi0,psi1,psi1}))
 +</code>
 +
 +==== Result ====
 +<file Quanty_Output>
 +The expectation value of a single state
 +-0.5
 +The expectation value of a single state with two other states
 +{ 0 , 0.5 }
 +The expectation value of a two states with two other states
 +{ { 0 , (0 + 0.5 I) , (0 + 0.5 I) } , 
 +  { (0 - 0.5 I) , 0 , 0 } }
 +</file>
 +
 +===== Table of contents =====
 +{{indexmenu>.#1}}
  
Print/export