Esempio n. 1
0
        static void Main()
        {
            double[] a       = { 1.1, 2.1, 4, 7.5 };
            Vector   vector1 = new Vector(a);

            double[] b       = { 3, 4, 5, 6, 7 };
            Vector   vector2 = new Vector(b);

            double[] c       = { 1, 1, 1 };
            Vector   vector3 = new Vector(c);

            Console.WriteLine(new Vector(6));
            Console.WriteLine(new Vector(vector2));
            Console.WriteLine(new Vector(a));
            Console.WriteLine(vector1);
            Console.WriteLine(new Vector(6, b));

            Console.WriteLine("Размерность вектора vector2: {0}", vector2.GetSize());

            vector1.SetElement(1, 10);
            Console.WriteLine("Значение вектора на 2 позиции: {0}", vector1.GetElement(1));

            vector2.Add(vector1);
            Console.WriteLine("Суммирование к вектору vector2 вектора vector1: {0}", vector2);

            vector2.Substract(vector1);
            Console.WriteLine("Вычитание от вектора vector2 вектора vector1: {0}", vector2);

            vector2.MultiplyByScalar(3);
            Console.WriteLine("Умножение вектора vector2 на скаляр: {0}", vector2);

            vector2.Reverse();
            Console.WriteLine("Обращение вектора vector2: {0}", vector2);
            Console.WriteLine("Длина вектора vector2: {0}", vector2.GetLength());
            Console.WriteLine("Сравнение на равенство векторов vector1 и vector2: {0}", vector1.Equals(vector2));
            Console.WriteLine("Хэш код вектора vector1: {0}", vector1.GetHashCode());
            Console.WriteLine(vector1);
            Console.WriteLine(vector2);
            Console.WriteLine("Суммирование вектора vector2 и вектора vector1: {0}", Vector.GetSum(vector1, vector2));
            Console.WriteLine("Вычитание вектора vector1 и вектора vector2: {0}", Vector.GetDifference(vector1, vector2));
            Console.WriteLine("Умножение вектора vector2 и вектора vector1: {0}", Vector.GetScalarMultiplication(vector1, vector2));

            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Vector vector0 = null;
            Vector vector1 = null;
            Vector vector2 = null;
            Vector vector3 = null;
            Vector vector4 = null;

            try
            {
                vector0 = new Vector(new double[] { 1, 2, 3 });
                vector2 = new Vector(5, new double[] { 1, 2, 9, 10 });
                vector3 = new Vector(new double[] { 1, 1, 1 });
                vector4 = new Vector(5, new double[] { 1, 8 });
                vector1 = new Vector(0);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Вектор: {0}.", vector2.ToString());
            Console.WriteLine("Хеш-код: {0}.", vector2.GetHashCode());
            Console.WriteLine("Размер: {0}.", vector2.Length);
            Console.WriteLine("Сумма векторов {0} и {1} равна {2}.", vector2.ToString(), vector3.ToString(), vector2.GetSum(vector3).ToString());
            Console.WriteLine("Вектор {0}, умноженный на скаляр {1} равен {2}.", vector2.ToString(), 2, vector2.MultiplyByScalar(2).ToString());
            Console.WriteLine("Скалярное произведение векторов {0} и {1} равно {2}.", vector3, vector2, Vector.GetScalarMultiplication(vector3, vector2));
        }
Esempio n. 3
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));
        }