I think this question is a bit low brow for the forum. I want to take a state vector $ \alpha |0\rangle + \beta |1\rangle $ to the two bloch angles. What's the best way? I tried to just factor out the phase from $\alpha$, but then ended up with a divide by zero when trying to compute $\phi$ from $\beta$.
3 Answers
You are probably dividing by $\alpha$ at some point to eliminate a global phase, leading to your divide by zero in some cases. It would be better to get the phase angles of $\alpha$ and $\beta$ with $\arg$, and set the relative phase $\phi=\arg(\beta)-\arg(\alpha)$. Angle $\theta$ is now simply extracted as $\theta = 2\cos^{-1}(|\alpha|)$ (note that the absolute value of $\alpha$ is used). This is all assuming that you want to get to
$$|\psi\rangle = \cos(\theta/2)|0\rangle + \mathrm{e}^{i\phi}\sin(\theta/2)|1\rangle\,,$$
which neglects global phase.
-
1$\begingroup$ Your previous questions suggest that you are using Matlab, which has the
angle()
function for calculatingarg
. In other languages that support complex types,arg
(or something similar such ascarg
for C99 complex doubles) is more common. $\endgroup$– qubyteCommented May 10, 2012 at 4:21
$\phi$ is the relative phase between $\alpha$ and $\beta$ (so the phase of $\alpha/\beta$). You will only get zero or divide-by-zero when $\alpha=0$ or $\beta=0$. But in that case, $\phi$ is arbitrary. And when $\alpha$ or $\beta$ are close to zero, you are near the poles of the Bloch sphere, and $\phi$ doesn't really matter that much.
To those who may be having a similar question: make sure you are normalizing the qubit before trying to find the Bloch angles.
Take for example the eigenvectors of the $X$ operator (Pauli matrix $\sigma^x$), in the $\{|0\rangle, |1\rangle\}$ basis:
$$ -|0\rangle + |1\rangle \\ |0\rangle + |1\rangle $$
If you try to use those coefficients directly, you will try for example $\cos \theta/2 = \pm 1$, which will lead to the inconsistent equation that the question mentions. But the right coefficients, after normalizing, should be:
$$ -\frac{ 1}{ \sqrt{2}}|0\rangle + \frac{ 1}{ \sqrt{2}}|1\rangle \\ \frac{ 1}{ \sqrt{2}}|0\rangle + \frac{ 1}{ \sqrt{2}}|1\rangle $$
These give you the correct positions in the Bloch sphere: $(\pi/2,\pi),(\pi/2,0)$
ll do that more. I didn
t understand that I could give back to people answering simply by upping their numbers. I like the community and will try to do better as a member $\endgroup$