Example #1
0
 def test_mult(self):
     # Test 1
     result = complex.mult([5, 2], [3, 1])
     self.assertEqual(result, [13, 11])
     # Test 2
     result = complex.mult([27, 12], [13, 1])
     self.assertEqual(result, [339, 183])
     # Test 3
     result = complex.mult([4, -3], [1, 10])
     self.assertEqual(result, [34, 37])
Example #2
0
def transition(ket1, ket2):
    braket2 = bra(vm.transpose(ket2)[0])
    norm1 = vm.vector_norm(vm.transpose(ket1)[0])
    norm2 = vm.vector_norm(vm.transpose(ket2)[0])
    norm = norm1 * norm2
    aux = vm.transpose(ket1)
    prob = vm.dot_product(braket2, vm.transpose(ket1)[0])
    ans = com.mult([1 / norm, 0], prob)
    return ans
Example #3
0
def additive_inverse(v):
    """
    Returns the additive inverse of a vector
    :Array v: Array of n items, each item is a complex number
    :return Array:
    """
    ans_vector = []
    for i in range(len(v)):
        ans_vector.append(complex.mult(v[i], [-1, 0]))
    return ans_vector
Example #4
0
def mult_escalar(c, v):
    """
    Multiplies a scalar number by a complex vector
    :List c: List of two items, first one the real part and second one the imaginary part
    :Array v: Array of n items, each item is a complex number
    :return Array:
    """
    ans_vector = []
    for i in range(len(v)):
        ans_vector.append(complex.mult(c, v[i]))
    return ans_vector
Example #5
0
def additive_inverse_mat(m):
    """
    Returns the additive inverse of a complex matrix
    :Array v: Matrix of n*m items, each item is a complex number
    :return Array:
    """
    ans = []
    for i in range(len(m)):
        ans.append([])
        for j in range(len(m[i])):
            ans[i].append(complex.mult(m[i][j], [-1, 0]))
    return ans
Example #6
0
def mult_escalar_mat(c, m):
    """
    Multiplies a scalar number by a complex matrix
    :List c: List of two items, first one the real part and second one the imaginary part
    :Array m: Array of n*m items, each item is a complex number
    :return Array:
    """
    ans_vector = []
    for i in range(len(m)):
        ans_vector.append([])
        for j in range(len(m[i])):
            ans_vector[i].append(complex.mult(c, m[i][j]))
    return ans_vector
Example #7
0
def dot_product(v1, v2):
    """
    Function that returns the dot product between two vectors
    :Array v1: Array of n items, each item is a complex number
    :Array v2: Array of n items, each item is a complex number
    :return Array:
    """
    if len(v1) == len(v2):
        ans = [0, 0]
        for i in range(len(v1)):
            ans = complex.add(ans, complex.mult(v1[i], v2[i]))
        return ans
    else:
        return 'Not possible'
Example #8
0
def mult_mat(m1, m2):
    """
    Function that multiplies two matrices
    :Array m1: Array of n*m items, each item is a complex number
    :Array m2: Array of n*m items, each item is a complex number
    :return Array:
    """
    if len(m1[0]) == len(m2):
        ans = [[[0, 0] for j in range(len(m2[0]))] for i in range(len(m1))]
        for i in range(len(m1)):
            for j in range(len(m2[0])):
                for k in range(len(m1[0])):
                    ans[i][j] = complex.add(ans[i][j], complex.mult(m1[i][k], m2[k][j]))
        return ans
    else:
        return 'Not possible'