Пример #1
0
 public void CheckVectorMatrixDimensionsEqual(Vector v)
 {
     if(this.DimensionCount != v.DimensionCount)
     {
         throw new ArgumentException("Different dimensions of vector or matrix.");
     }
 }
Пример #2
0
        public Vector Add(Vector Y)
        {
            CheckLengthEqual(Y);
            float[] total = new float[this.DimensionCount];
            for (int i = 0; i < this.DimensionCount; i++)
            {
                total[i] = this.coordinates[i] + Y.coordinates[i];
            }

            return new Vector(total);
        }
Пример #3
0
        public Vector ReadVector(StreamReader vectorReader, string filename)
        {
            vectorReader = this.OpenFile(filename);
            string sizeStr = vectorReader.ReadLine();
            int size = int.Parse(sizeStr);
            string coord = vectorReader.ReadLine();
            string[] coords = coord.Split();

            Vector X = new Vector(size);
            for (int i = 0; i < coords.Length; i++)
            {
                float comp = float.Parse(coords[i]);
                X[i] = comp;
            }

            return X;
        }
Пример #4
0
 public Vector Multiply(Vector X)
 {
     CheckVectorMatrixDimensionsEqual(X);
     float[] total = new float[this.DimensionCount];
     for (int i = 0; i < this.DimensionCount; i++)
     {
         for (int j = 0; j < this.DimensionCount; j++)
         {
             total[i] += this.components[i, j] * X[j];
         }
     }
     return new Vector(total);
 }
Пример #5
0
 private void CheckLengthEqual(Vector other)
 {
     if (this.DimensionCount != other.DimensionCount)
         throw new ArgumentException("Different length of vectors.");
 }
Пример #6
0
        public float Multiply(Vector Y)
        {
            CheckLengthEqual(Y);
            float total = 0;
            for (int i = 0; i < this.DimensionCount; i++)
            {
                total += this.coordinates[i] * Y.coordinates[i];
            }

            return total;
        }