Example #1
0
// MatrixComplexMultiSimple is an operation that will multiple two complex matrices of any size together
func MatrixComplexMultiSimple(matrixA ct.MatrixComplex, matrixB ct.MatrixComplex) (ct.MatrixComplex, error) {
	if matrixA.GetNumCols() != matrixB.GetNumRows() {
		return nil, errors.New("Length of columns of matrix A not equal to length of rows of matrix B")
	}

	if matrixA.IsIdentity() {
		return matrixB, nil
	}

	if matrixB.IsIdentity() {
		return matrixA, nil
	}

	var sum complex128

	matrixAB := ct.MakeComplexMatrix(matrixA.GetNumRows(), matrixB.GetNumRows())

	for i := 0; i < matrixA.GetNumRows(); i++ {
		for j := 0; j < matrixB.GetNumCols(); j++ {
			sum = 0.0
			for k := 0; k < matrixA.GetNumCols(); k++ {
				sum += matrixA.Get(i, k) * matrixB.Get(k, j)
			}
			matrixAB.Set(i, j, sum)
		}
	}

	return matrixAB, nil
}