Esempio n. 1
0
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, this))
            {
                return(true);
            }

            if (ReferenceEquals(obj, null) || obj.GetType() != this.GetType())
            {
                return(false);
            }

            Vector vector = (Vector)obj;

            if (vector.Length != Length)
            {
                return(false);
            }
            else
            {
                for (int i = 0; i < Length; i++)
                {
                    if (vector.GetComponent(i) != GetComponent(i))
                    {
                        return(false);
                    }
                }

                return(true);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            double[] arrayOfVectors = { 21, 17, 33, 41, 2, 3, 6, 9 };
            int      n = 0;

            for (int i = 0; i < arrayOfVectors.Length; i++)
            {
                n++;
            }

            Vector vector  = new Vector(arrayOfVectors);
            Vector vector1 = new Vector(vector);
            Vector vector2 = new Vector(n);
            Vector vector3 = new Vector(n, arrayOfVectors);

            Console.WriteLine("Vector size=" + vector1.GetSize());

            double[] arrayOfVectors1 = { 21, 17, 33, 41, 2, 3, 6, 9 };
            Vector   vector4         = new Vector(arrayOfVectors1);

            Console.WriteLine("Equals=" + vector1.Equals(vector4));

            Console.WriteLine("Sum of vectors=" + vector1.GetAddition(vector4));
            Console.WriteLine("Difference of vecrotrs=" + vector.GetDifference(vector4));

            double scalar = 3;

            Console.WriteLine("Vector multiplied by scalar=" + vector.GetMultipliedByScalar(scalar));

            Console.WriteLine("Vector rotation=" + vector.GetRotation());
            Console.WriteLine("Vector length=" + vector.GetLength());

            Console.WriteLine(vector.GetComponent(2));
            vector.SetComponent(2, 4);

            Console.WriteLine("Static sum of vectors=" + Vector.GetAdditionVectors(vector1, vector4));
            Console.WriteLine("Static difference of vecrotrs=" + Vector.GetDifferenceVectors(vector1, vector4));
            Console.WriteLine("Scalar multiplied of vectors=" + Vector.GetVectorMultipliedByAnotherVector(vector1, vector4));
            Console.Read();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            double[] arrayVectors = { 21, 17, 33, 41, 2, 3, 6, 9 };
            int      n            = 0;

            for (int i = 0; i < arrayVectors.Length; i++)
            {
                n++;
            }

            Vector vector  = new Vector(arrayVectors);
            Vector vector1 = new Vector(vector);
            Vector vector2 = new Vector(n);
            Vector vector3 = new Vector(n, arrayVectors);

            Console.WriteLine("Размер Вектора=" + vector1.GetSize());

            double[] arrayVectors1 = { 21, 17, 33, 41, 2, 3, 6, 9 };
            Vector   vector4       = new Vector(arrayVectors1);

            Console.WriteLine("Equals=" + vector1.Equals(vector4));

            Console.WriteLine("Сумма векторов=" + vector1.GetAddition(vector4));
            Console.WriteLine("Разница векторов=" + vector.GetDifference(vector4));

            double scalar = 3;

            Console.WriteLine("Скалярное умножение векторов=" + vector.GetMultipliedByScalar(scalar));

            Console.WriteLine("Разворот векторов=" + vector.GetRotation());
            Console.WriteLine("Длинна векторов=" + vector.GetLength());

            Console.WriteLine(vector.GetComponent(2));
            vector.SetComponent(2, 4);

            Console.WriteLine("Статическая сумма векторов=" + Vector.GetAdditionVectors(vector1, vector4));
            Console.WriteLine("Статическая разница векторов=" + Vector.GetDifferenceVectors(vector1, vector4));
            Console.WriteLine("Скалярное статическое умножение векторов=" + Vector.GetVectorMultipliedByAnotherVector(vector1, vector4));
            Console.Read();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Vector vector1 = new Vector(6);
            Vector vector2 = new Vector(vector1);
            Vector vector3 = new Vector(new double[] { 56.77, 7.5, 86.8, 6.7, 4.6, 66.8, 90.6, 12.4 });
            Vector vector4 = new Vector(6, new double[] { 5.6, 7.7, 6.8 });

            Console.Write("Сумма векторов {0} и {1} = ", vector3, vector4);
            vector3.AddVector(vector4);
            Console.WriteLine(vector3);
            Console.WriteLine();

            Console.Write("Разность векторов {0} и {1} = ", vector3, vector4);
            vector3.SubtractVector(vector4);
            Console.WriteLine(vector3);
            Console.WriteLine();

            int scalar = 10;

            Console.Write("Результат умножения вектора {0} на число {1} = ", vector4, scalar);
            vector4.MultiplyByScalar(scalar);
            Console.WriteLine(vector4);
            Console.WriteLine();

            Console.Write("Результат разворота вектора {0} = ", vector3);
            vector3.RotateVector();
            Console.WriteLine(vector3);
            Console.WriteLine();

            Console.WriteLine("Длина вектора {0} = {1}", vector3, vector3.GetLength());
            Console.WriteLine();

            Console.WriteLine("Третья компонента вектора {0} = {1}", vector3, vector3.GetComponent(3));
            Console.WriteLine();

            vector3.SetComponent(3, 45.3);

            Console.WriteLine("Третья компонента вектора теперь равна {0} = {1}", vector3, vector3.GetComponent(3));
            Console.WriteLine();

            Console.WriteLine("Сумма векторов {0} и {1} = {2}", vector3, vector4, Vector.AddVectors(vector3, vector4));
            Console.WriteLine();

            Console.WriteLine("Разность векторов {0} и {1} = {2}", vector3, vector4, Vector.SubtractVectors(vector3, vector4));
            Console.WriteLine();

            Console.WriteLine("Произведение векторов {0} и {1} = {2}", vector3, vector4, Vector.MultiplyVectors(vector3, vector4));
            Console.WriteLine();

            if (vector1.Equals(vector2))
            {
                Console.WriteLine("Векторы {0} и {1} равны", vector1, vector2);
            }
            else
            {
                Console.WriteLine("Векторы {0} и {1} не равны", vector1, vector2);
            }

            Console.WriteLine();

            if (vector1.Equals(vector3))
            {
                Console.WriteLine("Векторы {0} и {1} равны", vector1, vector3);
            }
            else
            {
                Console.WriteLine("Векторы {0} и {1} не равны", vector1, vector3);
            }

            try
            {
                Vector vector5 = new Vector(-2);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Размерность меньше 1. Вектор не создан.");
            }

            try
            {
                Vector vector6 = new Vector(-3, new double[] { 2.3 });
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Размерность меньше 1. Вектор не создан.");
            }

            try
            {
                Vector vector7 = new Vector(2);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Размерность меньше 1. Вектор не создан.");
            }

            Console.ReadKey();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Vector zerowVector = new Vector(3);

            Console.WriteLine("zerowVector = " + zerowVector);
            Console.WriteLine(new string('-', 100));

            double[] array           = { 3, 3.75, 2, 44, -5, 54 };
            Vector   arrayVector     = new Vector(array);
            Vector   copyArrayVector = new Vector(arrayVector);

            Console.WriteLine("arrayVector = " + arrayVector);
            Console.WriteLine("copyArrayVector = " + copyArrayVector);
            Console.WriteLine(new string('-', 100));

            Vector partialArrayVector = new Vector(8, array);

            Console.WriteLine("partialTestVector = " + partialArrayVector);
            Console.WriteLine("Размерность partialTesVector = " + partialArrayVector.GetSize());
            Console.WriteLine(new string('-', 100));

            Vector firstVector  = new Vector(new double[] { 3, 3, 4, 4 });
            Vector secondVector = new Vector(new double[] { 1, 3, 7, 8, 8, 8, 4 });

            Console.WriteLine("Сумма векторов {0} и {1} равна:", firstVector, secondVector);
            firstVector.Sum(secondVector);
            Console.WriteLine(firstVector);
            Console.WriteLine(new string('-', 100));

            Console.WriteLine("Разность векторов {0} и {1} равна:", firstVector, secondVector);
            firstVector.Subtract(secondVector);
            Console.WriteLine(firstVector);
            Console.WriteLine(new string('-', 100));

            double scalar = 3;

            Console.WriteLine("Результат умножения вектора {0} на скаляр {1}: ", firstVector, scalar);
            firstVector.MultiplicationByNumber(scalar);
            Console.WriteLine(firstVector);
            Console.WriteLine(new string('-', 100));

            Console.WriteLine("Вектор обратный вектору {0}:", firstVector);
            firstVector.Turn();
            Console.WriteLine(firstVector);
            Console.WriteLine(new string('-', 100));

            Console.WriteLine("Длина вектора {0} : {1:f2}", firstVector, firstVector.GetLength());
            int componentIndex = 3;

            Console.WriteLine("Компонента вектора {0} по индексу {1} : {2}", firstVector, componentIndex, firstVector.GetComponent(componentIndex));
            double newComponent = 55.6;

            firstVector.SetComponent(componentIndex, newComponent);
            Console.WriteLine("Компонента вектора {0} по индексу {1} : {2}", firstVector, componentIndex, firstVector.GetComponent(componentIndex));
            Console.WriteLine(new string('-', 100));

            if (firstVector.Equals(secondVector))
            {
                Console.WriteLine("Вектор {0} равен вектору {1}", firstVector, secondVector);
            }
            else
            {
                Console.WriteLine("Вектор {0} не равен вектору {1}", firstVector, secondVector);
            }
            Console.WriteLine("hashCode вектора {0}: {1}", firstVector, firstVector.GetHashCode());
            Console.WriteLine("hashCode вектора {0}: {1}", secondVector, secondVector.GetHashCode());
            Console.WriteLine(new string('-', 100));

            Console.WriteLine("Сумма векторов {0} и {1} равна: {2}", firstVector, secondVector, Vector.GetSum(firstVector, secondVector));
            Console.WriteLine("Разность векторов {0} и {1} равна: {2}", Vector.GetSum(firstVector, secondVector), firstVector, Vector.GetResidual(Vector.GetSum(firstVector, secondVector), firstVector));
            Console.WriteLine("Скалярное произведение векторов {0} и {1}: {2}", firstVector, secondVector, Vector.GetScalarMultiplication(firstVector, secondVector));
        }