public void CheckVectorMatrixDimensionsEqual(Vector v) { if(this.DimensionCount != v.DimensionCount) { throw new ArgumentException("Different dimensions of vector or matrix."); } }
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); }
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; }
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); }
private void CheckLengthEqual(Vector other) { if (this.DimensionCount != other.DimensionCount) throw new ArgumentException("Different length of vectors."); }
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; }