예제 #1
0
        public void ShouldDivide()
        {
            try
            {
                MatLib.divide(1, 0);
                Assert.Fail("Chyba, delenie nulou.");
            }
            catch
            {
            }

            try
            {
                MatLib.divide(-549.41268, 0);
                Assert.Fail("Chyba, delenie nulou.");
            }
            catch
            {
            }

            Assert.AreEqual(1, MatLib.divide(1, 1));
            Assert.AreEqual(100, MatLib.divide(100, 1));
            Assert.AreEqual(0.01, MatLib.divide(1, 100), Accuracy);
            Assert.AreEqual(5, MatLib.divide(50, 10));
            Assert.AreEqual(-5, MatLib.divide(50, -10));
            Assert.AreEqual(5, MatLib.divide(-50, -10));
            Assert.AreEqual(0, MatLib.divide(0, 10));
            Assert.AreEqual(10, MatLib.divide(5, 0.5), Accuracy);
            Assert.AreEqual(100, MatLib.divide(1, 0.01), Accuracy);
            Assert.AreEqual(0.6480482716, MatLib.divide(4.4893192, 6.92744568), Accuracy);

            Assert.AreNotEqual(0.6, MatLib.divide(4.4893192, 6.92744568), Accuracy);
            Assert.AreNotEqual(0.4, MatLib.divide(0.1601, 4));
            Assert.AreNotEqual(10, MatLib.divide(0, 10));
        }
예제 #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);
        }
예제 #3
0
        /**
         * @brief Výpočet aritmetického priemeru
         *
         * @param list Zoznam double, z ktorého vypočítať priemer
         * @return Aritmetický priemer
         */
        public static double GetArithmeticMean(List <double> list)
        {
            int    N = list.Count;
            double res = 0, sum = 0;

            for (int i = 0; i < N; i++)
            {
                sum = MatLib.add(sum, list[i]);
            }
            try
            {
                res = MatLib.divide(sum, N);
            }
            catch (DivideByZeroException e)
            {
                Console.WriteLine("{0}", e.Message);
                Console.WriteLine("Press any key to continue . . .");
                Console.Read();
                Environment.Exit(-1);
            }
            return(res);
        }