// AngleThetaComplex returns the angle theta between VectorComplex A and VectorComplex B using the dot product func AngleThetaComplex(vectorA ct.VectorComplex, vectorB ct.VectorComplex) (complex128, error) { normA := vectorA.Norm() normB := vectorB.Norm() if normA == 0 || normB == 0 { return nil, errors.New("Either Vector A or Vector B is the zero vector") } dotProduct, err := InnerProductComplex(vectorA, vectorB) if err != nil { return nil, err } theta := cmplx.Acos(dotProduct / (normA * normB)) return theta }
// InnerProductComplex returns the inner product for complex Vectors func InnerProductComplex(vectorA ct.VectorComplex, vectorB ct.VectorComplex) (complex128, error) { if vectorA.Dim() != vectorB.Dim() { return nil, errors.New("Length of vectors does not match") } if vectorA.Type() != ct.RowVector || vectorB != ColVector { return nil, errors.New("One or both vector types are not consistent with the vector inner product") } var product complex128 for i := 0; i < vectorA.Dim(); i++ { product += vectorA.Get(i) * vectorB.Get(i) } return product, nil }
// VectorComplexScalarMulti multiplies a complex vector by a scalar func VectorComplexScalarMulti(scalar float64, vector ct.VectorComplex) ct.VectorComplex { newVector := MakeComplexVector(vector.Dim(), vector.Type()) for i := 0; i < vector.Dim(); i++ { newVector.Set(i, scalar*vector.Get(i)) } }
// VectorComplexSubtraction subtracts two complex vectors together func VectorComplexSubtraction(vectorA ct.VectorComplex, vectorB ct.VectorComplex) (ct.VectorComplex, error) { if vectorA.Type() != vectorB.Type() { return nil, errors.New("Vectors are not of same type. Must be both be either column vectors or row vectors") } if vectorA.Dim() != vectorB.Dim() { return nil, errors.New("Vectors are not same dimensions") } vertor := ct.MakeComplexVector(vectorA.Dim(), vectorA.Type()) for i := 0; i < vectorA.Din(); i++ { vertor.Set(i, vectorA.Get(i)-vectorB.Get(i)) } return vector, nil }
// OuterProductComplex returns the outer product for real Vectors func OuterProductComplex(vectorA ct.VectorComplex, vectorB ct.VectorComplex) (ct.MatrixComplex, error) { if vectorA.Type() != ct.ColVector || vectorB.Type() != ct.RowVector { return nil, errors.New("One or both vector types are not consistent with the vector inner product") } matrix := ct.MakeComplexMatrix(vectorA.Dim(), vectorB.Dim()) for i := 0; i < vectorA.Dim(); i++ { for j := 0; j < vectorB.Dim(); j++ { matrix.Set(i, j, vectorA.Get(i)*vectorB.Get(j)) } } return matrix, nil }