Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In quantum computing, a qubit plays the role of a bit. It is a complex number a

ID: 3567516 • Letter: I

Question

In quantum computing, a qubit plays the role of a bit. It is a complex number a + bi such that |a + bi| = 1. The standard measurement operation of a qubit will result a 1 with probability a 2 and a 0 with probability b 2. Implement a class Qubit that has a constructor Qubit(a, b) and a boolean method observe that returns true or false with the probabilities described above. The initial values a and b can be anything but you must normalize them so that |a+bi| = 1. After normalizing the vector, you can observe the qubit.To implement this function, you need to generate a random number from 0 to 1, and return 1 if this random number is smaller than a^2( therefore a^2 of chance you will get a 1).

Explanation / Answer

class Qubit{
private double a,b;

public Qubit(double a,double b){
double den = Math.sqrt((a*a) + (b*b));
this.a = (a/den);
this.b = (b/den);
}

public boolean observe(){
Random rand = new Random();
if(Math.pow(rand.nextDouble(),7) < a*a){
return true;
}
else
return false;
}

}

Note the random generated is almost alwas greater than a^2. Thus it is scaled downed to power of 7 for better comparision. Typical values of a^2 are 0.0000087123.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote