Exemplo n.º 1
0
        public void ShouldSubtract()
        {
            Assert.AreEqual(10, MatLib.subtract(10, 0));
            Assert.AreEqual(-10, MatLib.subtract(0, 10));
            Assert.AreEqual(0, MatLib.subtract(5, 5));
            Assert.AreEqual(0, MatLib.subtract(0, 0));
            Assert.AreEqual(20000000, MatLib.subtract(60000000, 40000000));
            Assert.AreEqual(-0.2, MatLib.subtract(0.4, 0.6), Accuracy);
            Assert.AreEqual(0.2, MatLib.subtract(-0.4, -0.6), Accuracy);
            Assert.AreEqual(-2.43812648, MatLib.subtract(4.4893192, 6.92744568), Accuracy);
            Assert.AreEqual(2.43812648, MatLib.subtract(-4.4893192, -6.92744568), Accuracy);

            Assert.AreNotEqual(0, MatLib.subtract(10, -10));
            Assert.AreNotEqual(0, MatLib.subtract(-10, 10));
            Assert.AreNotEqual(10, MatLib.subtract(-10, 20));
            Assert.AreNotEqual(-50, MatLib.subtract(0, -50.0000357));
        }
Exemplo n.º 2
0
        /**
         * @brief Výpočet smerodajnej odchýlky
         *
         * @param list Zoznam double, z ktorého vypočítať smerodajnú odchýlku
         * @return Smerodajná odchýlka
         */
        public static double GetStandartDeviation(List <double> list)
        {
            int    N   = list.Count;
            double tmp = MatLib.subtract(GetSumSqr(list), MatLib.multiply(N, MatLib.square(GetArithmeticMean(list))));

            try
            {
                tmp = MatLib.divide(tmp, N - 1);
            }
            catch (DivideByZeroException e)
            {
                Console.WriteLine("{0}", e.Message);
                Console.WriteLine("Press any key to continue . . .");
                Console.Read();
                Environment.Exit(-1);
            }

            tmp = MatLib.sqrt(tmp);
            return(tmp);
        }