Example #1
0
func juliaSinIter(c, seed complex128) float64 {
	i := 0
	for z := c; cmplx.Abs(z) < 50 && i < maxIter; i++ {
		z = cmplx.Sin(z) * seed
	}

	return float64(maxIter-i) / maxIter
}
Example #2
0
// Convenience constructor for a qubit, specified by its spherical coordinates
// on the Bloch sphere.
func NewQubitWithBlochCoords(theta, phi float64) *QReg {
	// |psi> = cos(theta/2) + e^{i phi}sin(theta/2)
	t := complex(theta/2, 0)
	p := complex(phi, 0)
	qreg := &QReg{1, []complex128{cmplx.Cos(t),
		cmplx.Exp(complex(0, 1)*p) * cmplx.Sin(t)}}
	return qreg
}
Example #3
0
// Function to compute basis transformation matrix
func BasisTransform(th, phi float64) *[2][2]complex128 {

	BTMatrix := new([2][2]complex128)
	th_2, phi_2 := 0.5*th, 0.5*phi
	csn := cmplx.Cos(complex(th_2, 0.0)) * cmplx.Exp(complex(0.0, -1.0*phi_2))
	sn := cmplx.Sin(complex(th_2, 0.0)) * cmplx.Exp(complex(0.0, phi_2))

	BTMatrix[0][0] = cmplx.Conj(csn)
	BTMatrix[0][1] = cmplx.Conj(sn)
	BTMatrix[1][0] = complex(-1.0, 0.0) * sn
	BTMatrix[1][1] = csn

	return BTMatrix
}