示例#1
0
        public double Calculate()
        {
            double x1;
            double Xp        = dane.GetXp();
            double Xk        = dane.GetXk();
            double Precision = dane.GetPrecision();

            do
            {
                x1 = (Xp + Xk) / 2;
                if (dane.getFunctionInPointX(x1) == 0)
                {
                    return(x1);
                }
                if (dane.getFunctionInPointX(x1) * dane.getFunctionInPointX(Xp) < 0)
                {
                    Xk = x1;
                }
                else if (dane.getFunctionInPointX(x1) * dane.getFunctionInPointX(Xk) < 0)
                {
                    Xp = x1;
                }
            } while (Math.Abs(Xp - Xk) > Precision);
            return(Math.Round((Xp + Xk) / 2, Precision.ToString().Length - 2));
        }
示例#2
0
        public double Calculate()
        {
            double x1        = -1;
            double x2        = 1;
            double Precision = dane.GetPrecision();

            do
            {
                x1 = x2;
                x2 = x1 - dane.getFunctionInPointX(x1) / dane.getDerivativeInPoint(x1);
                if (Math.Abs(x2 - x1) <= Precision)
                {
                    break;
                }
                if (Math.Abs(dane.getFunctionInPointX(x1)) <= Precision)
                {
                    break;
                }
            } while (true);
            return(Math.Round(x2, 0));
        }