protected VectorSet(VectorSet a) { Size = a.Dimension; Ponderance = new double[Dimension]; for (int i = 0; i < Dimension; i++) { Ponderance[i] = a[i]; } }
/// <summary> /// Multiplies a vector by a scalar to produce a new vector. /// </summary> /// <param name="a">A scalar.</param> /// <param name="b">A vector.</param> /// <returns>The vector <paramref name="a"/>*<paramref name="b"/>.</returns> public static Vector Multiply(double a, VectorSet b) { Vector v = new Vector(b.Dimension); for (int i = 0; i < b.Dimension; i++) { v[i] = b[i] * a; } return(v); }
/// <summary> /// Determines whether two vectors are exactly equal. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns><c>true</c> if the two vectors are equal; otherwise, <c>false</c>.</returns> public static bool Compare(VectorSet a, VectorSet b) { if ((object)a == null && (object)b == null) { return(true); } else if ((object)a == null && (object)b != null) { return(false); } else { return(a.Equals(b)); } }
/// <summary> /// Returns the dot product of two vectors. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns>The dot product of <paramref name="a"/> and <paramref name="b"/>.</returns> public static double Dot(VectorSet a, VectorSet b) { if (a.Dimension != b.Dimension) { throw (new DimensionsNotEqualException()); } double d = 0.0; for (int i = 0; i < a.Dimension; i++) { d += a[i] * b[i]; } return(d); }
/// <summary> /// Adds two vectors to produce a new vector. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns>The vector <paramref name="a"/> + <paramref name="b"/>.</returns> public static Vector Add(VectorSet a, VectorSet b) { if (a.Dimension != b.Dimension) { throw (new DimensionsNotEqualException()); } Vector v = new Vector(a.Dimension); for (int i = 0; i < ((VectorSet)a).Dimension; i++) { v[i] = a[i] + b[i]; } return(v); }
/// <summary> /// Negate a vector. /// </summary> /// <param name="v">A vector.</param> /// <returns>The vector -<paramref name="v"/>.</returns> public static Vector Negate(VectorSet a) { return(Multiply(-1, a)); }
/// <summary> /// The opposite direction of the vector. /// </summary> /// <returns>new vector.</returns> public Vector OppositeDirections() { return(VectorSet.Negate(this)); }
/// <summary> /// Adds two vectors to produce a new vector. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns>The vector <paramref name="a"/> + <paramref name="b"/>.</returns> public static Vector Add(VectorSet a, VectorSet b) { if (a.Dimension != b.Dimension) { throw (new DimensionsNotEqualException()); } Vector v = new Vector(a.Dimension); for (int i = 0; i < ((VectorSet)a).Dimension; i++) { v[i] = a[i] + b[i]; } return v; }
/// <summary> /// Subtracts a vector from a vector to produce a new vector. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns>The vector <paramref name="a"/> - <paramref name="b"/>.</returns> public static Vector Subtract(VectorSet a, VectorSet b) { return Add(a, Negate(b)); }
/// <summary> /// Negate a vector. /// </summary> /// <param name="v">A vector.</param> /// <returns>The vector -<paramref name="v"/>.</returns> public static Vector Negate(VectorSet a) { return Multiply(-1, a); }
/// <summary> /// Multiplies a vector by a scalar to produce a new vector. /// </summary> /// <param name="a">A scalar.</param> /// <param name="b">A vector.</param> /// <returns>The vector <paramref name="a"/>*<paramref name="b"/>.</returns> public static Vector Multiply(double a, VectorSet b) { Vector v = new Vector(b.Dimension); for (int i = 0; i < b.Dimension; i++) { v[i] = b[i] * a; } return v; }
/// <summary> /// Returns the dot product of two vectors. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns>The dot product of <paramref name="a"/> and <paramref name="b"/>.</returns> public static double Dot(VectorSet a, VectorSet b) { if (a.Dimension != b.Dimension) { throw (new DimensionsNotEqualException()); } double d = 0.0; for (int i = 0; i < a.Dimension; i++) { d += a[i] * b[i]; } return d; }
/// <summary> /// Determines whether two vectors are exactly equal. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns><c>true</c> if the two vectors are equal; otherwise, <c>false</c>.</returns> public static bool Compare(VectorSet a, VectorSet b) { if ((object)a == null && (object)b == null) { return true; } else if ((object)a == null && (object)b != null) { return false; } else { return a.Equals(b); } }
public Vector(VectorSet a) : base(a) { }
/// <summary> /// Subtracts a vector from a vector to produce a new vector. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns>The vector <paramref name="a"/> - <paramref name="b"/>.</returns> public static Vector Subtract(VectorSet a, VectorSet b) { return(Add(a, Negate(b))); }