Пример #1
0
def productoInterno(v1,v2):
    if (len(v1) == len(v2)):
        vconj = conjugado(v1)
        rta = [0,0]
        for i in range(len(v1)):
            rta = complejos.suma(rta,complejos.multiplicacion(vconj[i],v2[i]))
        return rta 
    return None
Пример #2
0
 def test_multplicarEscalarPorMatriz(self):
     N = 4
     matriz = [[[random.randint(-100, 100),
                 random.randint(-100, 100)] for j in range(N)]
               for i in range(N)]
     inversa = [[]]
     escalar = [random.randint(-100, 100), random.randint(-100, 100)]
     matriz_resultado = matrices.multiplicarPorEscalar(escalar, matriz)
     for i in range(N):
         for j in range(N):
             self.assertEqual(basic.multiplicacion(matriz[i][j], escalar),
                              matriz_resultado[i][j])
Пример #3
0
def multiplicar(m1, m2):
    if (len(m1[0]) == len(m2)):
        matriz = crearMatrizVacia(len(m1), len(m2[0]))
        for i in range(len(m1)):
            for j in range(len(m2[0])):
                acumulador = [0, 0]
                for k in range(len(m1[0])):
                    acumulador = complejos.suma(
                        acumulador,
                        complejos.multiplicacion(m1[i][k], m2[k][j]))
                matriz[i][j] = acumulador
        return matriz
    return None
Пример #4
0
    def test_productoTensorVectores(self):
        N = 100
        vector = []
        vector2 = []
        for i in range(N):
            vector.append(
                [random.randint(-100, 100),
                 random.randint(-100, 100)])
            vector2.append(
                [random.randint(-100, 100),
                 random.randint(-100, 100)])
        rta = vectores.productoTensor(vector, vector2)

        tensor = []
        for i in range(N):
            for j in range(N):
                tensor.append(basic.multiplicacion(vector[i], vector2[j]))

        self.assertEqual(rta, tensor)
Пример #5
0
    def test_productoInterno(self):
        N = 100
        vector = []
        vector2 = []
        for i in range(N):
            vector.append(
                [random.randint(-100, 100),
                 random.randint(-100, 100)])
            vector2.append(
                [random.randint(-100, 100),
                 random.randint(-100, 100)])

        rta = vectores.productoInterno(vector, vector2)
        conjugado = vectores.conjugado(vector)
        suma = [0, 0]
        for i in range(N):
            suma = basic.suma(suma,
                              basic.multiplicacion(conjugado[i], vector2[i]))

        self.assertEqual(suma, rta)
Пример #6
0
def multiplicarPorEscalar(c,v):
    vector = []
    for i in range  (len(v)):
        vector.append(complejos.multiplicacion(c,v[i]))
    return vector
Пример #7
0
def productoTensor(v1,v2):
    vector = []
    for i in range (len(v1)):
        for j in range(len(v2)):
            vector.append(complejos.multiplicacion(v1[i],v2[j]))
    return vector
Пример #8
0
 def test_mult(self):
     c = complex(-2, 1) * complex(1, 2)
     rta = basic.multiplicacion([-2, 1], [1, 2])
     c1 = complex(rta[0], rta[1])
     self.assertEqual(c1, c)