0

I have been trying to rotate spherical coordinates using quantum physics. I followed the following post on how to do this: https://stla.github.io/stlapblog/posts/RotationSphericalCoordinates.html

I have some knowledge about quantum physics but very limited. Here is what I came up with in C# (sorry about indentation):

public Complex[,] rotationsMatrixX = new Complex[2, 2];
public Complex[,] rotationsMatrixY = new Complex[2, 2];
public Complex[,] rotationsMatrixZ = new Complex[2, 2];

public void rotatemethod(){
//Initialize the rotation matrices

double angle = 30;

//init X
rotationsMatrixX[0, 0] = new Complex(Math.Cos(angle / 2), 0);
rotationsMatrixX[0, 1] = new Complex(0, -Math.Sin(angle / 2));
rotationsMatrixX[1, 0] = new Complex(0, -Math.Sin(angle / 2));
rotationsMatrixX[1, 1] = new Complex(Math.Cos(angle / 2), 0);

//init Y
rotationsMatrixY[0, 0] = new Complex(Math.Cos(angle / 2), 0);
rotationsMatrixY[0, 1] = new Complex(-Math.Sin(angle / 2), 0);
rotationsMatrixY[1, 0] = new Complex(Math.Sin(angle / 2), 0);
rotationsMatrixY[1, 1] = new Complex(Math.Cos(angle / 2), 0);

//init Z
rotationsMatrixZ[0, 0] = new Complex(Math.Cos(angle / 2), -Math.Sin(angle / 2));
rotationsMatrixZ[0, 1] = new Complex(0, 0);
rotationsMatrixZ[1, 0] = new Complex(0, 0);
rotationsMatrixZ[1, 1] = new Complex(Math.Cos(angle / 2), Math.Sin(angle / 2));

double theta = 0.20943951023932; // 0 <= phi <= 2PI (for now just sample input)
double phi = 4.93055513688398;   // 0 <= theta <= Pi (for now just sample input)

Console.WriteLine(" theta " + theta + " phi: " + phi);

//validation checks
if (theta < 0 || theta > Math.PI || phi < 0 || phi > 2 * Math.PI)
{
    throw new ArgumentOutOfRangeException("phi and/or theta out of bounds");
}

//create the qubit
Complex topQbit = new Complex(Math.Cos(theta/2),0);
Complex bottomQbit = new Complex(Math.Cos(phi)*Math.Sin(theta/2), Math.Sin(phi)*Math.Sin(theta/2));

Complex[] quBit = new Complex[2];
quBit[0] = topQbit;
quBit[1] = bottomQbit;

Complex[] rotatedQbit = MultiplyComplexMatrix(quBit, rotationsMatrixY);

Complex[] rotatedQbit = MultiplyComplexMatrix(quBit, rotationsMatrixY);

//not sure if I need Atan2 here..
double rotatedTheta = 2 * Math.Atan(Complex.Abs(rotatedQbit[1]) / Complex.Abs(rotatedQbit[0])); 
double rotatedPhi = rotatedQbit[1].Phase - rotatedQbit[0].Phase;
}



//Matrix Multiplication (with Complex numbers ONLY)
        public Complex[] MultiplyComplexMatrix(Complex[] quBit, Complex[,] rotationMatrix)
        {
            //the rotated qbit
            Complex[] rotatedQbit = new Complex[2];

            //just some naming to make matrix multiplication more readable
            Complex A = quBit[0];
            Complex B = quBit[1];
            Complex C = rotationMatrix[0, 0];
            Complex D = rotationMatrix[0, 1];
            Complex E = rotationMatrix[1, 0];
            Complex F = rotationMatrix[1, 1];

            rotatedQbit[0] = Complex.Multiply(A, B) + Complex.Multiply(B, E);
            rotatedQbit[1] = Complex.Multiply(A, D) + Complex.Multiply(B, F);

            return rotatedQbit;
        }

The results (below) I am getting do not make any sense. I would apparitie any help! or an alternative to achieving this.

RESULTS FROM SAMPLE INPUT (rotating over Y with angle=30):

starting with C: 232.5 G: 124----------------
theta 2.16420827247297 phi: 4.05789051088682
the rotatedTheta is: 1.00298077136411 and the rotatedPhi is: 3.60482234077516
in degrees:
theta 124 phi: 232.5
the rotatedTheta is: 57.466565131939 and the rotatedPhi is: 206.541106020887
ending with C: 232.5 G: 124----------------
starting with C: 232.5 G: 126----------------
theta 2.19911485751286 phi: 4.05789051088682
the rotatedTheta is: 1.01877652772437 and the rotatedPhi is: 3.58185846568257
in degrees:
theta 126 phi: 232.5
the rotatedTheta is: 58.3715953055989 and the rotatedPhi is: 205.225372896816
ending with C: 232.5 G: 126----------------
starting with C: 232.5 G: 128----------------
theta 2.23402144255274 phi: 4.05789051088682
the rotatedTheta is: 1.03535071902231 and the rotatedPhi is: 3.55952053311715
in degrees:
theta 128 phi: 232.5
the rotatedTheta is: 59.3212265158133 and the rotatedPhi is: 203.94550363777
ending with C: 232.5 G: 128----------------
starting with C: 232.5 G: 130----------------
theta 2.26892802759263 phi: 4.05789051088682
the rotatedTheta is: 1.05269513187015 and the rotatedPhi is: 3.53779163501912
in degrees:
theta 130 phi: 232.5
the rotatedTheta is: 60.3149881701271 and the rotatedPhi is: 202.700529483282
ending with C: 232.5 G: 130----------------

0 Answers0