Esempio n. 1
0
// VectorSubtraction subtracts two real vectors together
func VectorSubtraction(vectorA ct.Vector, vectorB ct.Vector) (ct.Vector, 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.MakeVector(vectorA.Dim(), vectorA.Type())

	for i := 0; i < vectorA.Din(); i++ {
		vertor.Set(i, vectorA.Get(i)-vectorB.Get(i))
	}

	return vector, nil
}