Quest
Quest

Reputation: 33

Values of ket vectors in Julia

I can't figure out how to get specific elements/ values of a ket vector in Julia language. I tried to call a specific index of the ket vector using [index], like one does with a regular vector, but that does not seem to work with kets.

Kets are available in the QuantumOptics.jl package. So for a simple example, if I would define a ket myself:

basis = FockBasis(2)
x = Ket(basis, [1,3,2])

which gives output:

Ket(dim=3)
 basis: Fock(cutoff=2)
 1.0
 3.0
 2.0

If I then try to get an element of the ket, I would try it like this:

x[1]

which gives an error:

MethodError: no method matching getindex(::Ket{FockBasis{Int64},Array{Int64,1}}, ::Int64)

and I can't access the seperate elements of the ket.

Upvotes: 3

Views: 114

Answers (1)

Uziel Linares
Uziel Linares

Reputation: 98

Maybe the easiest way to get the j coefficient for a ket is just to access the j value for the data property of the ket. For your example you can just do

j = 1
j_coeff = x.data[j]

Upvotes: 1

Related Questions