Example #1
0
        public double LOperator(MathFunction yx, double x)
        {
            MathFunction der2 = yx.Derivative(2),
                         der1 = yx.Derivative(1);

            return(der2.Calculate(x) + PX.Calculate(x) * der1.Calculate(x) +
                   QX.Calculate(x) * yx.Calculate(x));
        }
        public double Solve(Equasion eq, double a, double b)
        {
            MathFunction func = eq.Left - eq.Right;

            MathFunction der1 = func.Derivative(1),
                         der2 = func.Derivative(2);

            if (!IsSuitable(der1, a, b) ||
                !IsSuitable(der2, a, b))
                throw new Exception("Method can not be applied!");

            MathFunction ksi = IterationFunc(der1, a, b);

            double x0 = InitialX(func, a, b);

            return GenericIterationMethod(func, ksi, a, b, x0);
        }
        public double Solve(Equasion eq, double a, double b)
        {
            MathFunction func = eq.Left - eq.Right;

            MathFunction der1 = func.Derivative(1),
                         der2 = func.Derivative(2);

            if (!IsSuitable(der1, a, b) ||
                !IsSuitable(der2, a, b))
            {
                throw new Exception("Method can not be applied!");
            }

            double c = SuitableRandomArgumnent((double x) => { return(func.Calculate(x) * der2.Calculate(x) > 0); }, a, b);

            MathFunction ksi = IterationFunc(func, a, b, c);

            double x0 = InitialX(func, a, b, c);

            return(GenericIterationMethod(func, ksi, a, b, x0));
        }
        protected virtual double GenericIterationMethod(MathFunction func, MathFunction ksi, double a, double b, double x0)
        {
            double xn = x0, counter = 0;
            double fDerivativeMin = func.Derivative(1).MinValue(a, b);

            MathFunction iterFunc = new XFunction(1.0d) + ksi * func;

            do
            {
                xn = iterFunc.Calculate(xn);
                counter++;
            } while (counter < maxIterationCount && !(Math.Abs(func.Calculate(xn)) / fDerivativeMin <= epsilanIter));

            if (counter == maxIterationCount)
            {
                return(xn);                             //  double.PositiveInfinity;
            }
            return(xn);
        }
Example #5
0
        private static MathFunction <BigFloat> CalculateFunction(int power, BigFloat point, ref MathFunction <BigFloat> function, ref int curPower)
        {
            function = function.Derivative(power - curPower);
            curPower = power;
            BigFloat value = function.Calculate(point);

            BigInteger fact = Factorial.Calculate(power);

            value /= fact;

            if (power == 0)
            {
                return(value);
            }
            else if (power == 1)
            {
                return(value * (new XFunction <BigFloat>(1.0) - point));
            }
            else
            {
                return(new PowerFunction <BigFloat>(value, new XFunction <BigFloat>(1.0) - point, (BigFloat)power));
            }
        }
 protected double InitialX(MathFunction func, double a, double b)
 {
     return SuitableRandomArgumnent((double arg) => { return func.Calculate(arg) * func.Derivative(2).Calculate(arg) < 0; }, a, b);
 }