示例#1
0
 protected VectorSet(VectorSet a)
 {
     Size       = a.Dimension;
     Ponderance = new double[Dimension];
     for (int i = 0; i < Dimension; i++)
     {
         Ponderance[i] = a[i];
     }
 }
示例#2
0
 protected VectorSet(VectorSet a)
 {
     Size = a.Dimension;
     Ponderance = new double[Dimension];
     for (int i = 0; i < Dimension; i++)
     {
         Ponderance[i] = a[i];
     }
 }
示例#3
0
        /// <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);
        }
示例#4
0
 /// <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));
     }
 }
示例#5
0
        /// <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);
        }
示例#6
0
        /// <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);
        }
示例#7
0
 /// <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));
 }
示例#8
0
 /// <summary>
 /// The opposite direction of the vector.
 /// </summary>
 /// <returns>new vector.</returns>
 public Vector OppositeDirections()
 {
     return(VectorSet.Negate(this));
 }
示例#9
0
        /// <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;
        }
示例#10
0
 /// <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));
 }
示例#11
0
 /// <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);
 }
示例#12
0
        /// <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;
        }
示例#13
0
        /// <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;
        }
示例#14
0
 /// <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);
     }
 }
示例#15
0
 public Vector(VectorSet a)
     : base(a)
 {
 }
示例#16
0
 /// <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)));
 }
示例#17
0
 public Vector(VectorSet a) : base(a)
 {
 }