Esempio n. 1
0
        public double CountIntegralForCore(int kindOfCore)
        {
            Func <double, double> core;
            NumericalDerivative   derivative       = new NumericalDerivative(10, 5);
            Func <double, double> fourthDerivative = derivative.CreateDerivativeFunctionHandle(Func, 4); //CountDerivative(func, 4);
            Func <double, double> thirdDerivative  = derivative.CreateDerivativeFunctionHandle(Func, 3); //CountDerivative(func, 3);
            Func <double, double> secondDerivative = derivative.CreateDerivativeFunctionHandle(Func, 2); //CountDerivative(func, 2);

            //Console.WriteLine("fourthDerivative = " + fourthDerivative(1.57));
            //Console.WriteLine("thirdDerivative = " + thirdDerivative(1.57));
            //Console.WriteLine("secondDerivative = " + secondDerivative(1.57));
            if (kindOfCore == 1)
            {
                core = (x) => { return(fourthDerivative(x) - ((Math.Pow(thirdDerivative(x), 2)) / (secondDerivative(x + 0.00001)))); }
            }
            ;
            else
            {
                core = (x) => { return(fourthDerivative(x)); }
            };

            // Console.WriteLine("core = " + core(1));
            Func <double, double> underIntegralFunc = (x) => { return(Math.Pow(Math.Abs((core(x))), 0.25)); };
            double integralValue = CountIntegral(LeftLimit, RightLimit, underIntegralFunc, Precision);

            return(integralValue);
        }

        //public double Factorial(double number)
        //{
        //    double res = 1;
        //    double n = number;
        //    while (n != 1)
        //    {
        //        res *= n;
        //        n--;
        //    }
        //    return res;
        //}

        //public double ErrorCount(double integralValue, int parametersAmount, double r)
        //{
        //    double error = 0;

        //    // double integralValue = CountIntegral();
        //    error = ((Math.Pow(integralValue, parametersAmount)) / (Math.Pow(2, parametersAmount) * Factorial(parametersAmount) * Math.Pow(r, parametersAmount)));
        //    return error;
        //}
    }
        public void CreateDerivativeFunctionHandleTest()
        {
            Func <double, double> f = x => 3 * Math.Pow(x, 3) + 2 * x - 6;
            var nd = new NumericalDerivative(5, 2);
            var df = nd.CreateDerivativeFunctionHandle(f, 3);

            Assert.AreEqual(18, df(0));

            // Test new function with same nd class
            Func <double, double> f2 = x => 2 * Math.Pow(x, 3) + 2 * x - 6;
            var df2 = nd.CreateDerivativeFunctionHandle(f2, 3);

            Assert.AreEqual(12, df2(0));

            // Original delegate not changed
            Assert.AreEqual(18, df(0));
        }
        public void CreateDerivativeFunctionHandleTest()
        {
            Func<double, double> f = x => 3 * Math.Pow(x, 3) + 2 * x - 6;
            var nd = new NumericalDerivative(5, 2);
            var df = nd.CreateDerivativeFunctionHandle(f, 3);

            Assert.AreEqual(18, df(0));

            // Test new function with same nd class
            Func<double, double> f2 = x => 2 * Math.Pow(x, 3) + 2 * x - 6;
            var df2 = nd.CreateDerivativeFunctionHandle(f2, 3);

            Assert.AreEqual(12, df2(0));

            // Original delegate not changed
            Assert.AreEqual(18, df(0));
        }
Esempio n. 4
0
        public Func <double, double> CountCoreFunc(Func <double, double> func, int kindOfCore)
        {
            NumericalDerivative   derivative       = new NumericalDerivative(6, 3);
            Func <double, double> fourthDerivative = derivative.CreateDerivativeFunctionHandle(func, 4); //CountDerivative(func, 4);
            Func <double, double> thirdDerivative  = derivative.CreateDerivativeFunctionHandle(func, 3); //CountDerivative(func, 3);
            Func <double, double> secondDerivative = derivative.CreateDerivativeFunctionHandle(func, 2); //CountDerivative(func, 2);

            switch (kindOfCore)
            {
            case 1: { return((x) => { return (fourthDerivative(x) - Math.Pow(thirdDerivative(x), 2) / (secondDerivative(x))); }); }

            case 2: { return((x) => { return fourthDerivative(x); }); };

            default: break;
            }
            return(null);
        }
Esempio n. 5
0
        public static Func <double, double> Derive(Func <double, double> f, int deriveRank)
        {
            //Func<double, double> f = x => 3 * Math.Pow(x, 3) + 2 * x - 6;
            var n  = new NumericalDerivative(5, 2);
            var df = n.CreateDerivativeFunctionHandle(f, deriveRank);

            return(df);
        }
Esempio n. 6
0
        static public Func <double, double> FindDerivative(Func <double, double> function)
        {
            NumericalDerivative   derivative = new NumericalDerivative();
            Func <double, double> derivativeFunction;

            derivativeFunction = derivative.CreateDerivativeFunctionHandle(function, 1);
            return(derivativeFunction);
        }