dotProduct method
Calculates the dot product for two 3-dimensional vectors.
Throws MatrixInvalidDimensions if both vectors do not have the same number of elements.
final Vector a = Vector.column([2.0,3.0,4.0]);
final Vector b = Vector.column([5.0,6.0,7.0]);
print(a.crossProduct(b));
prints
56.0
Implementation
double dotProduct(Vector other) {
if (this.elements != other.elements) {
throw MatrixInvalidDimensions("Dot product requires both vectors to have the same number of elements.");
}
double p = 0.0;
for (int i = 0; i < this.elements; i++) {
p += this[i] * other[i];
}
return p;
}