/// <summary> /// creates a clone of this vector /// </summary> /// <returns>the cloned vector</returns> public Vector Clone() { Vector buffer = new Vector(Dimensions); for (int i = 0; i < Dimensions; i++) { buffer[i] = this[i]; } return buffer; }
/// <summary> /// calculates the scalar product of this vector with another vector /// </summary> /// <param name="other">the other vector of the product</param> /// <returns>the calculated scalar</returns> public double ScalarProduct(Vector other) { if (Dimensions != other.Dimensions) throw new DimensionMismatchException( "The scalar product can only be calculated for vectors of the same length"); double result = 0; for (int i = 0; i < Dimensions; i++) { result += this[i]*other[i]; } return result; }
public static Vector operator -(Vector v) { Vector buffer = new Vector(v.Dimensions); for (int i = 0; i < v.Dimensions; i++) { buffer[i] = -v[i]; } return buffer; }