beginner · Programming · The Qubit State Vector & Dirac Notation
Superposition with Arbitrary Weights
Not every useful qubit state has equal amplitudes. A superposition with arbitrary weights lets you
control exactly how much probability mass sits on ∣0⟩ versus ∣1⟩ — and that control is
at the heart of preparing initial states for quantum algorithms.
The general single-qubit state
Any normalized single-qubit state can be written as
∣ψ⟩=α∣0⟩+β∣1⟩,
where α,β∈C and the normalization condition
∣α∣2+∣β∣2=1
must hold so that the Born-rule probabilities sum to one. When the amplitudes are real and non-negative,
this is equivalent to writing α=cos(θ/2) and β=sin(θ/2) for some angle
θ∈[0,π], since cos2(θ/2)+sin2(θ/2)=1 by the Pythagorean identity.
The Ry rotation
The Ry(θ) gate rotates the Bloch-sphere state vector about the y-axis by angle θ. Its
matrix is
So choosing θ determines the split. When θ=π/2, we get
cos(π/4)=sin(π/4)=1/2 — the familiar 50/50 superposition from ∣0⟩. Note that
Ry(π/2) and the Hadamard gate H agree on ∣0⟩ but are different unitaries (H maps
∣1⟩→(∣0⟩−∣1⟩)/2, whereas Ry(π/2) maps ∣1⟩→(−∣0⟩+∣1⟩)/2).
Confirming normalization
Suppose you want the state ∣ψ⟩=23∣0⟩+21∣1⟩.
Check that it is normalized:
232+212=43+41=1.✓
To prepare it with Ry, set cos(θ/2)=3/2. Because cos(π/6)=3/2, we
have θ/2=π/6, so θ=π/3. The measurement probabilities are
P(0)=3/4 and P(1)=1/4.
Try it
Prepare the state ∣ψ⟩=23∣0⟩+21∣1⟩ by choosing
the right angle for an Ry rotation. The grader checks the full statevector, so the amplitudes must
match the target exactly (up to global phase).
Run your code to see the quantum state.
After running, inspect the statevector panel: you should see amplitudes close to 0.866≈3/2
on ∣0⟩ and 0.5 on ∣1⟩, with probabilities 0.75 and 0.25 respectively.
Sign in on the full site to ask questions and join the discussion.