A vector class, implementing all interesting features of vectors
Inheritance: IEnumerable, IComparable
Exemplo n.º 1
0
 /// <summary>
 /// Build a new vector as a copy of an existing one
 /// </summary>
 /// <param name="O">The existing vector</param>
 public Vector(Vector O)
     : this(O.data)
 {
 }
Exemplo n.º 2
0
 /// <summary>
 /// Reset all elements with ransom values from the given range
 /// </summary>
 /// <param name="MinMax">MinMax[0] - Min
 /// MinMax[1] - Max</param>
 public void Randomize(Vector[] MinMax)
 {
     int i;
     for(i=0;i<data.Length;i++)
     {
         this[i] = MinMax[0][i] + (MinMax[1][i] - MinMax[0][i]) * MathF.R.NextDouble();
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Add another vector
 /// </summary>
 /// <param name="V">V</param>
 public void Add(Vector V)
 {
     int i;
     for(i=0;i<data.Length;i++)
     {
         this[i] += V[i];
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Get the distance of two vectors
 /// </summary>
 public static double Dist(Vector V1, Vector V2)
 {
     if(V1.Dim != V2.Dim)
         return -1;
     int i;
     double E = 0,D;
     for(i=0;i<V1.Dim;i++)
     {
         D=(V1[i]-V2[i]);
         E+=D*D;
     }
     return E;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Subtract two vectors
 /// </summary>
 public static Vector operator -(Vector A, Vector B)
 {
     if(A.Dim!=B.Dim)
         throw new Exception("Vectors of different dimension!");
     Vector Erg = new Vector(A.Dim);
     int i;
     for(i=0;i<A.Dim;i++)
         Erg[i]=A[i]-B[i];
     return Erg;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Scale one vector
 /// </summary>
 public static Vector operator *(Vector A, double B)
 {
     Vector Erg = new Vector(A.Dim);
     int i;
     for(i=0;i<A.Dim;i++)
         Erg[i]=A[i]*B;
     return Erg;
 }