Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void ShouldSqrt()
        {
            Assert.AreEqual(0, MatLib.sqrt(0));
            Assert.AreEqual(1, MatLib.sqrt(1));
            Assert.AreEqual(1.414213562373, MatLib.sqrt(2), Accuracy);
            Assert.AreEqual(5, MatLib.sqrt(25));
            Assert.AreEqual(0.707106781186547, MatLib.sqrt(0.5), Accuracy);
            Assert.AreEqual(387.2989801174281, MatLib.sqrt(150000.5), Accuracy);

            Assert.AreNotEqual(1000, MatLib.sqrt(999999), Accuracy);

            try
            {
                MatLib.sqrt(-1);
                Assert.Fail("Chyba, nepatri do oboru realnych cisel.");
            }
            catch
            {
            }
        }