You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expectation value of the [`Operator`](@ref) `O` with the state `ψ`. The state can be a [`Ket`](@ref), [`Bra`](@ref) or [`Operator`](@ref).
23
23
@@ -27,48 +27,75 @@ If `ψ` is a density matrix ([`Operator`](@ref)), the function calculates ``\tex
27
27
28
28
The function returns a real number if `O` is of `Hermitian` type or `Symmetric` type, and returns a complex number otherwise. You can make an operator `O` hermitian by using `Hermitian(O)`.
29
29
30
-
Note that `ψ` can also be given as a list of [`QuantumObject`](@ref), it returns a list of expectation values.
30
+
!!! note "List of observables and states"
31
+
The observable `O` and state `ψ` can be given as a list of [`QuantumObject`](@ref), it returns a list of expectation values. If both of them are given as a list, it returns a `Matrix` of expectation values.
31
32
32
33
# Examples
33
34
34
35
```jldoctest
35
-
julia> ψ = 1 / √2 * (fock(10,2) + fock(10,4));
36
+
julia> ψ1 = 1 / √2 * (fock(10,2) + fock(10,4));
37
+
38
+
julia> ψ2 = coherent(10, 0.6 + 0.8im);
36
39
37
40
julia> a = destroy(10);
38
41
39
-
julia> expect(a' * a, ψ) |> round
42
+
julia> expect(a' * a, ψ1) |> round
40
43
3.0 + 0.0im
41
44
42
-
julia> expect(Hermitian(a' * a), ψ) |> round
45
+
julia> expect(Hermitian(a' * a), ψ1) |> round
43
46
3.0
47
+
48
+
julia> round.(expect([a' * a, a' + a, a], [ψ1, ψ2]), digits = 1)
0 commit comments