10 public class Vector : IEnumerable, IComparable
15 public static int Precision = 10;
17 public object Tag=null;
24 data =
new double[dim];
32 data =
new double[X.Length];
48 if(S[0]!=
'(' || S[S.Length-1]!=
')')
49 throw new Exception(
"Formatfehler!");
51 data =
new double[P.Length];
53 for(i=0;i<data.Length;i++)
55 data[i] =
double.Parse(P[i]);
61 public double this [
int i]
69 data[i] = Math.Round(value,Precision);
87 public double SquaredLength
98 public double ElementSum
117 for(i=0;i<data.Length;i++)
119 this[i] = Min + (Max-Min)*
MathTools.
R.NextDouble();
130 for(i=0;i<data.Length;i++)
132 this[i] = MinMax[0][i] + (MinMax[1][i]-MinMax[0][i])*
MathTools.
R.NextDouble();
142 for(i=0;i<data.Length;i++)
154 for(i=0;i<data.Length;i++)
166 for(i=0;i<data.Length;i++)
171 IEnumerator IEnumerable.GetEnumerator()
173 return data.GetEnumerator();
184 for(i=0;i<data.Length;i++)
186 S += data[i].ToString(
"G4");
202 if(B==null || data.Length != B.
data.Length)
205 for(i=0;i<data.Length;i++)
207 if(Math.Abs(data[i]-B.
data[i])>1e-10)
220 foreach(
double D
in data)
221 Erg = Erg ^ Math.Round(D,Precision).GetHashCode();
231 throw new Exception(
"Vectors of different dimension!");
245 throw new Exception(
"Vectors of different dimension!");
259 throw new Exception(
"Vectors of different dimension!");
289 public static explicit operator double[](
Vector A)
302 for(i=0;i<V1.
Dim;i++)
318 if(A==null || B==null)
Vector(int dim)
Build a new vector
static string[] HighLevelSplit(string S, params char[] C)
A vector class, implementing all interesting features of vectors
double SquaredLength
The squared length of the vector
override string ToString()
Convert the vector into a reconstructable string representation
virtual Vector Clone()
Get a copy of one vector
void Randomize(Vector[] MinMax)
Reset all elements with ransom values from the given range
override bool Equals(object obj)
Compares this vector with another one
int CompareTo(object obj)
Compare two vectors
void Add(Vector V)
Add another vector
Vector(params double[] X)
Build a new vector
void Randomize(double Min, double Max)
Reset all elements with ransom values from the given range
override int GetHashCode()
Retrieves a hashcode that is dependent on the elements
int Dim
The dimension of the vector
static double Dist(Vector V1, Vector V2)
Get the distance of two vectors
void Add(double d)
Add a constant to all elements
void Multiply(double r)
Scale all elements by r
Vector(string S)
Build a new vector from a string
Vector(Vector O)
Build a new vector as a copy of an existing one
static readonly Random R
One static Random instance for use in the entire application