Ejemplo n.º 1
0
        public int QuadrInterpExtrap()
        {
            double h, _a, _b, _c, _d;
            int    k = 1;

            Func.interp d1 = Func.d1;
            Func.interp d2 = Func.d2;
            _b = (a + b) / 2;
            h  = 0.01 * Math.Abs(_b);
            while (true)
            {
                _a = _b - h;
                _c = _b + h;
                _d = d1(f, _a, _b, _c);
                k++;
                if (Math.Abs((_b - _d)) / Math.Abs(_b) <= Eps && Math.Abs((f(_b) - f(_d))) / Math.Abs(f(_b)) <= Eps)
                {
                    x_min = (_b + _d) / 2;
                    break;
                }
                else
                {
                    _b = _d;
                }
            }
            return(k);
        }
Ejemplo n.º 2
0
        public int Pauell(int max) //Реализация алгоритма Пауэлла
        {
            double E1 = Math.Pow(10, -3);
            double E2 = E1;
            double _a, _b, _c, _d;
            int    k = 1;

            Func.interp d1 = Func.d1;
            Func.interp d2 = Func.d2;

            _a = a;
            _c = b;
            _b = (_a + _c) / 2;

            while (true)
            {
                if (k == 1)
                {
                    _d = d1(f, _a, _b, _c);
                }

                else
                {
                    _d = d2(f, _a, _b, _c);
                }

                if (Math.Abs((_b - _d)) / Math.Abs(_b) <= Eps || Math.Abs((f(_b) - f(_d))) / Math.Abs(f(_b)) <= Eps)
                {
                    a     = (_b < _d) ? _b : _d;
                    b     = (_b > _d) ? _b : _d;
                    x_min = (_b + _d) / 2;
                    break;
                }

                else
                {
                    if (_b < _d)
                    {
                        if (f(_b) < f(_d))
                        {
                            _c = _d;
                        }
                        else
                        {
                            _a = _b;
                            _b = _d;
                        }
                    }
                    else
                    {
                        if (f(_b) < f(_d))
                        {
                            _a = _d;
                        }
                        else
                        {
                            _c = _b;
                            _b = _d;
                        }
                    }
                }
                k++;
            }
            return(k);
        }
Ejemplo n.º 3
0
        public int DSK(int max)
        {
            int    k = 1;
            double h;
            double x1, x2, x3, x4;
            double _a, _b, _c, d;

            Func.interp d4 = Func.d4;

            x1 = (a + b) / 2;
            x2 = 0;
            x3 = 0;
            if (x1 != 0)
            {
                h = 0.001 * Math.Abs(x1);
            }
            else
            {
                h = 0.001;
            }

            //Основной этап
            while (true)
            {
                k  = Svenn_2(h, ref x1, ref x2, ref x3);
                x4 = (x3 + x2) / 2;
                if (f(x2) < f(x4))
                {
                    _a = x1;
                    _b = x2;
                    _c = x4;
                }
                else
                {
                    _a = x2;
                    _b = x4;
                    _c = x3;
                }
                d = d4(f, _a, _b, _c);
                if (((Math.Abs((d - _b) / _b)) <= Eps) || (Math.Abs((f(d) - f(_b)) / f(_b)) <= Eps) || k >= max)
                {
                    x_min = (_b + d) / 2;
                    break;
                }
                else
                {
                    if (f(_b) < f(d))
                    {
                        x1 = _b;
                    }
                    else
                    {
                        x1 = d;
                    }
                }
                h = h / 2;
                k++;
            }
            //Console.WriteLine("k = {0}",k);
            return(k);
        }