public void Sum(Vector vector) { MakeAlignment(vector.GetSize()); for (int i = 0; i < vector.GetSize(); i++) { Components[i] += vector.Components[i]; } }
public void Difference(Vector vector) { MakeAlignment(vector.GetSize()); for (int i = 0; i < vector.GetSize(); i++) { Components[i] -= vector.Components[i]; } }
public void Subtract(Vector vector) { if (vector.GetSize() > coordinates.Length) { double[] newCoordinates = new double[vector.GetSize()]; coordinates.CopyTo(newCoordinates, 0); coordinates = newCoordinates; } for (int i = 0; i < vector.GetSize(); i++) { coordinates[i] -= vector.coordinates[i]; } }
public override bool Equals(object o) { if (ReferenceEquals(o, this)) { return(true); } if (ReferenceEquals(o, null) || o.GetType() != GetType()) { return(false); } Vector v = (Vector)o; if (coordinates.Length != v.GetSize()) { return(false); } for (int i = 0; i < coordinates.Length; i++) { if (coordinates[i] != v.GetCoordinate(i)) { return(false); } } return(true); }
static void Main(string[] args) { double[] array1 = { 4, 25, 18, 17, 32 }; double[] array2 = { 5, 67, 21, 12, 32 }; Vector vector1 = new Vector(6, array1); Vector vector2 = new Vector(4, array2); Vector vector3 = new Vector(vector1); Console.WriteLine("Вектор1: " + vector1); Console.WriteLine("Вектор1 размер: {0}, длина: {1}", vector1.GetSize(), vector1.GetVectorLength()); Console.WriteLine("Вектор2: " + vector2); Console.WriteLine("Вектор2 размер: {0}, длина: {1}", vector2.GetSize(), vector2.GetVectorLength()); Console.WriteLine("Вектор3: " + vector3); Console.WriteLine("Вектор3 размер: {0}, длина: {1}", vector3.GetSize(), vector3.GetVectorLength()); Console.WriteLine("Хэшкод вектора 1: " + vector1.GetHashCode()); Console.WriteLine("Равенство векторов 1 и 3: " + vector1.Equals(vector3)); Console.WriteLine("Добавляем вектор 2 к 1: " + vector1.AddVector(vector2)); Console.WriteLine("Вычитаем вектор 2 из 3: " + vector3.SubtractVector(vector2)); Vector vector4 = Vector.GetVectorSum(vector2, vector3); Console.WriteLine("Сумма вектора 2 и 3 (Вектор4): " + vector4); Vector vector5 = Vector.GetVectorSum(vector4, vector3); Console.WriteLine("Разность векторов 4 из 3 (Вектор5): " + vector5); Console.WriteLine("Произведение векторов 2 из 5: " + Vector.GetScalarMultiplication(vector2, vector5)); Console.ReadKey(); }
public override bool Equals(object obj) { if (ReferenceEquals(obj, this)) { return(true); } if (ReferenceEquals(obj, null) || GetType() != obj.GetType()) { return(false); } Vector vector = (Vector)obj; if (GetSize() != vector.GetSize()) { return(false); } for (int i = 0; i < GetSize(); i++) { if (Components[i] != vector.Components[i]) { return(false); } } return(true); }
public Vector(Vector vector) { int length = vector.GetSize(); Components = new double[length]; Array.Copy(vector.Components, Components, length); }
public Vector SubtractVector(Vector vector) { if (GetSize() < vector.GetSize()) { double[] valuesResult = new double[vector.GetSize()]; Array.Copy(Values, 0, valuesResult, 0, GetSize()); Values = valuesResult; } for (int i = 0; i < vector.GetSize(); i++) { Values[i] -= vector.Values[i]; } return(this); }
public Vector(Vector vector) { int coordinatesCount = vector.GetSize(); coordinates = new double[coordinatesCount]; vector.coordinates.CopyTo(coordinates, 0); }
public static double ScalarMultiplication(Vector firstVector, Vector secondVector) { double sumMultiplicationComponent = 0; int length = Math.Min(firstVector.GetSize(), secondVector.GetSize()); for (int i = 0; i < length; i++) { sumMultiplicationComponent += firstVector.Components[i] * secondVector.Components[i]; } return(sumMultiplicationComponent); }
public static double GetScalarMultiplication(Vector vector1, Vector vector2) { int vectorMinSize = Math.Min(vector1.GetSize(), vector2.GetSize()); double sum = 0; for (int i = 0; i < vectorMinSize; i++) { sum += vector1.Values[i] * vector2.Values[i]; } return(sum); }
public static double GetScalarMultiplication(Vector vector1, Vector vector2) { double scalar = 0; int smallerVectorSize = Math.Min(vector1.GetSize(), vector2.GetSize()); for (int i = 0; i < smallerVectorSize; i++) { scalar += vector1.GetCoordinate(i) * vector2.GetCoordinate(i); } return(scalar); }
static void Main(string[] args) { Vector vec1 = new Vector(5); Vector vec2 = new Vector(vec1); Vector vec3 = new Vector(new double[] { 1.2, 5.5, 4.7, 8, 6.4 }); Vector vec4 = new Vector(5, new double[] { 1, 2, 5, 4, 5 }); Vector sumTest1 = new Vector(7, new double[] { 1, 2, 3, 4, 5 }); Vector sumTest2 = new Vector(5, new double[] { 1, 2, 3, 4, 5 }); Vector vec5 = new Vector(5, new double[] { 1, 2, 5, 4, 5, 6, 7 }); Vector vec6 = new Vector(7, new double[] { 1, 2, 5, 4, 5 }); Vector vec7 = new Vector(7, new double[] { 1, 2, 5, 4, 5 }); Vector vec8 = new Vector(5, new double[] { 1, 2, 3, 4, 5 }); Vector vec9 = new Vector(7, new double[] { 4, 0, 6, 4, 5 }); Vector vec10 = new Vector(5, new double[] { 3, 2, 3, 4, 5 }); Vector vec11 = new Vector(7, new double[] { 1, 2, 3, 4, 5 }); Vector vec12 = new Vector(5, new double[] { 6, 6, 6, 1, 5 }); Vector vec13 = new Vector(15, new double[] { 9, 8, 0, 0, 5 }); sumTest1.Sum(sumTest2); vec6.Difference(vec7); vec8.Multiplication(10); int size = vec13.GetSize(); bool equals = vec4.Equals(vec5); double component = vec3.GetComponent(3); vec3.SetComponent(0, 100); vec12.Turn(); double length = vec11.GetLength(); Vector vector1 = Vector.Sum(vec5, vec7); Vector vector2 = Vector.Difference(vec5, vec4); double vector3 = Vector.ScalarMultiplication(vec4, vec5); vec4.SetComponent(0, 5); double vector4 = Vector.ScalarMultiplication(vec5, vec4); bool equals1 = vector3.Equals(vector4); Vector[] vectors = new Vector[] { vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9, vec10, vec11, vec12, vec13 }; foreach (Vector value in vectors) { Console.WriteLine(value + " " + value.GetSize()); } Console.ReadKey(); }
public override bool Equals(object obj) { if (ReferenceEquals(obj, this)) { return(true); } if (ReferenceEquals(obj, null) || obj.GetType() != GetType()) { return(false); } Vector vector = (Vector)obj; return(GetSize() == vector.GetSize() && elements.SequenceEqual(vector.elements)); }
public Vector(Vector vector) { Values = new double[vector.GetSize()]; Array.Copy(vector.Values, 0, Values, 0, vector.GetSize()); }