Beispiel #1
0
 /*************************************************************************
 *  Adaptive integration results
 *
 *  Called after AutoGKIteration returned False.
 *
 *  Input parameters:
 *   State   -   algorithm state (used by AutoGKIteration).
 *
 *  Output parameters:
 *   V       -   integral(f(x)dx,a,b)
 *   Rep     -   optimization report (see AutoGKReport description)
 *
 *  -- ALGLIB --
 *    Copyright 14.11.2007 by Bochkanov Sergey
 *************************************************************************/
 public static void autogkresults(ref autogkstate state,
                                  ref double v,
                                  ref autogkreport rep)
 {
     v = state.v;
     rep.terminationtype = state.terminationtype;
     rep.nfev            = state.nfev;
     rep.nintervals      = state.nintervals;
 }
Beispiel #2
0
 /*************************************************************************
 *  Integration of a smooth function F(x) on a finite interval [a,b].
 *
 *  This subroutine is same as AutoGKSmooth(), but it guarantees that interval
 *  [a,b] is partitioned into subintervals which have width at most XWidth.
 *
 *  Subroutine  can  be  used  when  integrating nearly-constant function with
 *  narrow "bumps" (about XWidth wide). If "bumps" are too narrow, AutoGKSmooth
 *  subroutine can overlook them.
 *
 *  INPUT PARAMETERS:
 *   A, B    -   interval boundaries (A<B, A=B or A>B)
 *
 *  OUTPUT PARAMETERS
 *   State   -   structure which stores algorithm state between  subsequent
 *               calls of AutoGKIteration.  Used for reverse communication.
 *               This structure should be  passed  to  the  AutoGKIteration
 *               subroutine.
 *
 *  SEE ALSO
 *   AutoGKSmooth, AutoGKSingular, AutoGKIteration, AutoGKResults.
 *
 *
 *  -- ALGLIB --
 *    Copyright 06.05.2009 by Bochkanov Sergey
 *************************************************************************/
 public static void autogksmoothw(double a,
                                  double b,
                                  double xwidth,
                                  ref autogkstate state)
 {
     state.wrappermode  = 0;
     state.a            = a;
     state.b            = b;
     state.xwidth       = xwidth;
     state.rstate.ra    = new double[10 + 1];
     state.rstate.stage = -1;
 }
Beispiel #3
0
 /*************************************************************************
 *  Integration on a finite interval [A,B].
 *  Integrand have integrable singularities at A/B.
 *
 *  F(X) must diverge as "(x-A)^alpha" at A, as "(B-x)^beta" at B,  with known
 *  alpha/beta (alpha>-1, beta>-1).  If alpha/beta  are  not known,  estimates
 *  from below can be used (but these estimates should be greater than -1 too).
 *
 *  One  of  alpha/beta variables (or even both alpha/beta) may be equal to 0,
 *  which means than function F(x) is non-singular at A/B. Anyway (singular at
 *  bounds or not), function F(x) is supposed to be continuous on (A,B).
 *
 *  Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
 *  is calculated with accuracy close to the machine precision.
 *
 *  INPUT PARAMETERS:
 *   A, B    -   interval boundaries (A<B, A=B or A>B)
 *   Alpha   -   power-law coefficient of the F(x) at A,
 *               Alpha>-1
 *   Beta    -   power-law coefficient of the F(x) at B,
 *               Beta>-1
 *
 *  OUTPUT PARAMETERS
 *   State   -   structure which stores algorithm state between  subsequent
 *               calls of AutoGKIteration.  Used for reverse communication.
 *               This structure should be  passed  to  the  AutoGKIteration
 *               subroutine.
 *
 *  SEE ALSO
 *   AutoGKSmooth, AutoGKSmoothW, AutoGKIteration, AutoGKResults.
 *
 *
 *  -- ALGLIB --
 *    Copyright 06.05.2009 by Bochkanov Sergey
 *************************************************************************/
 public static void autogksingular(double a,
                                   double b,
                                   double alpha,
                                   double beta,
                                   ref autogkstate state)
 {
     state.wrappermode  = 1;
     state.a            = a;
     state.b            = b;
     state.alpha        = alpha;
     state.beta         = beta;
     state.xwidth       = 0.0;
     state.rstate.ra    = new double[10 + 1];
     state.rstate.stage = -1;
 }
Beispiel #4
0
        /*************************************************************************
        Integration of a smooth function F(x) on a finite interval [a,b].

        Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
        is calculated with accuracy close to the machine precision.

        Algorithm works well only with smooth integrands.  It  may  be  used  with
        continuous non-smooth integrands, but with  less  performance.

        It should never be used with integrands which have integrable singularities
        at lower or upper limits - algorithm may crash. Use AutoGKSingular in such
        cases.

        INPUT PARAMETERS:
            A, B    -   interval boundaries (A<B, A=B or A>B)
            
        OUTPUT PARAMETERS
            State   -   structure which stores algorithm state

        SEE ALSO
            AutoGKSmoothW, AutoGKSingular, AutoGKResults.
            

          -- ALGLIB --
             Copyright 06.05.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void autogksmooth(double a,
            double b,
            autogkstate state)
        {
            alglib.ap.assert(math.isfinite(a), "AutoGKSmooth: A is not finite!");
            alglib.ap.assert(math.isfinite(b), "AutoGKSmooth: B is not finite!");
            autogksmoothw(a, b, 0.0, state);
        }
Beispiel #5
0
 public override alglib.apobject make_copy()
 {
     autogkstate _result = new autogkstate();
     _result.a = a;
     _result.b = b;
     _result.alpha = alpha;
     _result.beta = beta;
     _result.xwidth = xwidth;
     _result.x = x;
     _result.xminusa = xminusa;
     _result.bminusx = bminusx;
     _result.needf = needf;
     _result.f = f;
     _result.wrappermode = wrappermode;
     _result.internalstate = (autogkinternalstate)internalstate.make_copy();
     _result.rstate = (rcommstate)rstate.make_copy();
     _result.v = v;
     _result.terminationtype = terminationtype;
     _result.nfev = nfev;
     _result.nintervals = nintervals;
     return _result;
 }
Beispiel #6
0
        /*************************************************************************
        *  One step of adaptive integration process.
        *
        *  Called after initialization with one of AutoGKXXX subroutines.
        *  See HTML documentation for examples.
        *
        *  Input parameters:
        *   State   -   structure which stores algorithm state between  calls  and
        *               which  is  used  for   reverse   communication.   Must  be
        *               initialized with one of AutoGKXXX subroutines.
        *
        *  If suborutine returned False, iterative proces has converged. If subroutine
        *  returned True, caller should calculate function value State.F  at  State.X
        *  and call AutoGKIteration again.
        *
        *  NOTE:
        *
        *  When integrating "difficult" functions with integrable singularities like
        *
        *   F(x) = (x-A)^alpha * (B-x)^beta
        *
        *  subroutine may require the value of F at points which are too close to A/B.
        *  Sometimes to calculate integral with high enough precision we  may need to
        *  calculate F(A+delta) when delta is less than machine  epsilon.  In  finite
        *  precision arithmetics A+delta will be effectively equal to A,  so  we  may
        *  find us in situation when  we  are  trying  to  calculate  something  like
        *  1/sqrt(1-1).
        *
        *  To avoid  such  situations,  AutoGKIteration  subroutine  fills  not  only
        *  State.X  field,  but  also   State.XMinusA   (which  equals  to  X-A)  and
        *  State.BMinusX  (which  equals to B-X) fields.  If X is too close to A or B
        *  (X-A<0.001*A, or B-X<0.001*B, for example) use  these  fields  instead  of
        *  State.X
        *
        *
        *  -- ALGLIB --
        *    Copyright 07.05.2009 by Bochkanov Sergey
        *************************************************************************/
        public static bool autogkiteration(ref autogkstate state)
        {
            bool   result = new bool();
            double s      = 0;
            double tmp    = 0;
            double eps    = 0;
            double a      = 0;
            double b      = 0;
            double x      = 0;
            double t      = 0;
            double alpha  = 0;
            double beta   = 0;
            double v1     = 0;
            double v2     = 0;


            //
            // Reverse communication preparations
            // I know it looks ugly, but it works the same way
            // anywhere from C++ to Python.
            //
            // This code initializes locals by:
            // * random values determined during code
            //   generation - on first subroutine call
            // * values from previous call - on subsequent calls
            //
            if (state.rstate.stage >= 0)
            {
                s     = state.rstate.ra[0];
                tmp   = state.rstate.ra[1];
                eps   = state.rstate.ra[2];
                a     = state.rstate.ra[3];
                b     = state.rstate.ra[4];
                x     = state.rstate.ra[5];
                t     = state.rstate.ra[6];
                alpha = state.rstate.ra[7];
                beta  = state.rstate.ra[8];
                v1    = state.rstate.ra[9];
                v2    = state.rstate.ra[10];
            }
            else
            {
                s     = -983;
                tmp   = -989;
                eps   = -834;
                a     = 900;
                b     = -287;
                x     = 364;
                t     = 214;
                alpha = -338;
                beta  = -686;
                v1    = 912;
                v2    = 585;
            }
            if (state.rstate.stage == 0)
            {
                goto lbl_0;
            }
            if (state.rstate.stage == 1)
            {
                goto lbl_1;
            }
            if (state.rstate.stage == 2)
            {
                goto lbl_2;
            }

            //
            // Routine body
            //
            eps   = 0;
            a     = state.a;
            b     = state.b;
            alpha = state.alpha;
            beta  = state.beta;
            state.terminationtype = -1;
            state.nfev            = 0;
            state.nintervals      = 0;

            //
            // smooth function  at a finite interval
            //
            if (state.wrappermode != 0)
            {
                goto lbl_3;
            }

            //
            // special case
            //
            if ((double)(a) == (double)(b))
            {
                state.terminationtype = 1;
                state.v = 0;
                result  = false;
                return(result);
            }

            //
            // general case
            //
            autogkinternalprepare(a, b, eps, state.xwidth, ref state.internalstate);
lbl_5:
            if (!autogkinternaliteration(ref state.internalstate))
            {
                goto lbl_6;
            }
            x                  = state.internalstate.x;
            state.x            = x;
            state.xminusa      = x - a;
            state.bminusx      = b - x;
            state.rstate.stage = 0;
            goto lbl_rcomm;
lbl_0:
            state.nfev            = state.nfev + 1;
            state.internalstate.f = state.f;
            goto lbl_5;
lbl_6:
            state.v = state.internalstate.r;
            state.terminationtype = state.internalstate.info;
            state.nintervals      = state.internalstate.heapused;
            result = false;
            return(result);

lbl_3:

            //
            // function with power-law singularities at the ends of a finite interval
            //
            if (state.wrappermode != 1)
            {
                goto lbl_7;
            }

            //
            // test coefficients
            //
            if ((double)(alpha) <= (double)(-1) | (double)(beta) <= (double)(-1))
            {
                state.terminationtype = -1;
                state.v = 0;
                result  = false;
                return(result);
            }

            //
            // special cases
            //
            if ((double)(a) == (double)(b))
            {
                state.terminationtype = 1;
                state.v = 0;
                result  = false;
                return(result);
            }

            //
            // reduction to general form
            //
            if ((double)(a) < (double)(b))
            {
                s = +1;
            }
            else
            {
                s     = -1;
                tmp   = a;
                a     = b;
                b     = tmp;
                tmp   = alpha;
                alpha = beta;
                beta  = tmp;
            }
            alpha = Math.Min(alpha, 0);
            beta  = Math.Min(beta, 0);

            //
            // first, integrate left half of [a,b]:
            //     integral(f(x)dx, a, (b+a)/2) =
            //     = 1/(1+alpha) * integral(t^(-alpha/(1+alpha))*f(a+t^(1/(1+alpha)))dt, 0, (0.5*(b-a))^(1+alpha))
            //
            autogkinternalprepare(0, Math.Pow(0.5 * (b - a), 1 + alpha), eps, state.xwidth, ref state.internalstate);
lbl_9:
            if (!autogkinternaliteration(ref state.internalstate))
            {
                goto lbl_10;
            }

            //
            // Fill State.X, State.XMinusA, State.BMinusX.
            // Latter two are filled correctly even if B<A.
            //
            x       = state.internalstate.x;
            t       = Math.Pow(x, 1 / (1 + alpha));
            state.x = a + t;
            if ((double)(s) > (double)(0))
            {
                state.xminusa = t;
                state.bminusx = b - (a + t);
            }
            else
            {
                state.xminusa = a + t - b;
                state.bminusx = -t;
            }
            state.rstate.stage = 1;
            goto lbl_rcomm;
lbl_1:
            if ((double)(alpha) != (double)(0))
            {
                state.internalstate.f = state.f * Math.Pow(x, -(alpha / (1 + alpha))) / (1 + alpha);
            }
            else
            {
                state.internalstate.f = state.f;
            }
            state.nfev = state.nfev + 1;
            goto lbl_9;
lbl_10:
            v1 = state.internalstate.r;
            state.nintervals = state.nintervals + state.internalstate.heapused;

            //
            // then, integrate right half of [a,b]:
            //     integral(f(x)dx, (b+a)/2, b) =
            //     = 1/(1+beta) * integral(t^(-beta/(1+beta))*f(b-t^(1/(1+beta)))dt, 0, (0.5*(b-a))^(1+beta))
            //
            autogkinternalprepare(0, Math.Pow(0.5 * (b - a), 1 + beta), eps, state.xwidth, ref state.internalstate);
lbl_11:
            if (!autogkinternaliteration(ref state.internalstate))
            {
                goto lbl_12;
            }

            //
            // Fill State.X, State.XMinusA, State.BMinusX.
            // Latter two are filled correctly (X-A, B-X) even if B<A.
            //
            x       = state.internalstate.x;
            t       = Math.Pow(x, 1 / (1 + beta));
            state.x = b - t;
            if ((double)(s) > (double)(0))
            {
                state.xminusa = b - t - a;
                state.bminusx = t;
            }
            else
            {
                state.xminusa = -t;
                state.bminusx = a - (b - t);
            }
            state.rstate.stage = 2;
            goto lbl_rcomm;
lbl_2:
            if ((double)(beta) != (double)(0))
            {
                state.internalstate.f = state.f * Math.Pow(x, -(beta / (1 + beta))) / (1 + beta);
            }
            else
            {
                state.internalstate.f = state.f;
            }
            state.nfev = state.nfev + 1;
            goto lbl_11;
lbl_12:
            v2 = state.internalstate.r;
            state.nintervals = state.nintervals + state.internalstate.heapused;

            //
            // final result
            //
            state.v = s * (v1 + v2);
            state.terminationtype = 1;
            result = false;
            return(result);

lbl_7:
            result = false;
            return(result);

            //
            // Saving state
            //
lbl_rcomm:
            result              = true;
            state.rstate.ra[0]  = s;
            state.rstate.ra[1]  = tmp;
            state.rstate.ra[2]  = eps;
            state.rstate.ra[3]  = a;
            state.rstate.ra[4]  = b;
            state.rstate.ra[5]  = x;
            state.rstate.ra[6]  = t;
            state.rstate.ra[7]  = alpha;
            state.rstate.ra[8]  = beta;
            state.rstate.ra[9]  = v1;
            state.rstate.ra[10] = v2;
            return(result);
        }
    /*************************************************************************
    Integration on a finite interval [A,B].
    Integrand have integrable singularities at A/B.

    F(X) must diverge as "(x-A)^alpha" at A, as "(B-x)^beta" at B,  with known
    alpha/beta (alpha>-1, beta>-1).  If alpha/beta  are  not known,  estimates
    from below can be used (but these estimates should be greater than -1 too).

    One  of  alpha/beta variables (or even both alpha/beta) may be equal to 0,
    which means than function F(x) is non-singular at A/B. Anyway (singular at
    bounds or not), function F(x) is supposed to be continuous on (A,B).

    Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
    is calculated with accuracy close to the machine precision.

    INPUT PARAMETERS:
        A, B    -   interval boundaries (A<B, A=B or A>B)
        Alpha   -   power-law coefficient of the F(x) at A,
                    Alpha>-1
        Beta    -   power-law coefficient of the F(x) at B,
                    Beta>-1

    OUTPUT PARAMETERS
        State   -   structure which stores algorithm state

    SEE ALSO
        AutoGKSmooth, AutoGKSmoothW, AutoGKResults.


      -- ALGLIB --
         Copyright 06.05.2009 by Bochkanov Sergey
    *************************************************************************/
    public static void autogksingular(double a, double b, double alpha, double beta, out autogkstate state)
    {
        state = new autogkstate();
        autogk.autogksingular(a, b, alpha, beta, state.innerobj);
        return;
    }
Beispiel #8
0
        /*************************************************************************

          -- ALGLIB --
             Copyright 07.05.2009 by Bochkanov Sergey
        *************************************************************************/
        public static bool autogkiteration(autogkstate state)
        {
            bool result = new bool();
            double s = 0;
            double tmp = 0;
            double eps = 0;
            double a = 0;
            double b = 0;
            double x = 0;
            double t = 0;
            double alpha = 0;
            double beta = 0;
            double v1 = 0;
            double v2 = 0;

            
            //
            // Reverse communication preparations
            // I know it looks ugly, but it works the same way
            // anywhere from C++ to Python.
            //
            // This code initializes locals by:
            // * random values determined during code
            //   generation - on first subroutine call
            // * values from previous call - on subsequent calls
            //
            if( state.rstate.stage>=0 )
            {
                s = state.rstate.ra[0];
                tmp = state.rstate.ra[1];
                eps = state.rstate.ra[2];
                a = state.rstate.ra[3];
                b = state.rstate.ra[4];
                x = state.rstate.ra[5];
                t = state.rstate.ra[6];
                alpha = state.rstate.ra[7];
                beta = state.rstate.ra[8];
                v1 = state.rstate.ra[9];
                v2 = state.rstate.ra[10];
            }
            else
            {
                s = -983;
                tmp = -989;
                eps = -834;
                a = 900;
                b = -287;
                x = 364;
                t = 214;
                alpha = -338;
                beta = -686;
                v1 = 912;
                v2 = 585;
            }
            if( state.rstate.stage==0 )
            {
                goto lbl_0;
            }
            if( state.rstate.stage==1 )
            {
                goto lbl_1;
            }
            if( state.rstate.stage==2 )
            {
                goto lbl_2;
            }
            
            //
            // Routine body
            //
            eps = 0;
            a = state.a;
            b = state.b;
            alpha = state.alpha;
            beta = state.beta;
            state.terminationtype = -1;
            state.nfev = 0;
            state.nintervals = 0;
            
            //
            // smooth function  at a finite interval
            //
            if( state.wrappermode!=0 )
            {
                goto lbl_3;
            }
            
            //
            // special case
            //
            if( (double)(a)==(double)(b) )
            {
                state.terminationtype = 1;
                state.v = 0;
                result = false;
                return result;
            }
            
            //
            // general case
            //
            autogkinternalprepare(a, b, eps, state.xwidth, state.internalstate);
        lbl_5:
            if( !autogkinternaliteration(state.internalstate) )
            {
                goto lbl_6;
            }
            x = state.internalstate.x;
            state.x = x;
            state.xminusa = x-a;
            state.bminusx = b-x;
            state.needf = true;
            state.rstate.stage = 0;
            goto lbl_rcomm;
        lbl_0:
            state.needf = false;
            state.nfev = state.nfev+1;
            state.internalstate.f = state.f;
            goto lbl_5;
        lbl_6:
            state.v = state.internalstate.r;
            state.terminationtype = state.internalstate.info;
            state.nintervals = state.internalstate.heapused;
            result = false;
            return result;
        lbl_3:
            
            //
            // function with power-law singularities at the ends of a finite interval
            //
            if( state.wrappermode!=1 )
            {
                goto lbl_7;
            }
            
            //
            // test coefficients
            //
            if( (double)(alpha)<=(double)(-1) || (double)(beta)<=(double)(-1) )
            {
                state.terminationtype = -1;
                state.v = 0;
                result = false;
                return result;
            }
            
            //
            // special cases
            //
            if( (double)(a)==(double)(b) )
            {
                state.terminationtype = 1;
                state.v = 0;
                result = false;
                return result;
            }
            
            //
            // reduction to general form
            //
            if( (double)(a)<(double)(b) )
            {
                s = 1;
            }
            else
            {
                s = -1;
                tmp = a;
                a = b;
                b = tmp;
                tmp = alpha;
                alpha = beta;
                beta = tmp;
            }
            alpha = Math.Min(alpha, 0);
            beta = Math.Min(beta, 0);
            
            //
            // first, integrate left half of [a,b]:
            //     integral(f(x)dx, a, (b+a)/2) =
            //     = 1/(1+alpha) * integral(t^(-alpha/(1+alpha))*f(a+t^(1/(1+alpha)))dt, 0, (0.5*(b-a))^(1+alpha))
            //
            autogkinternalprepare(0, Math.Pow(0.5*(b-a), 1+alpha), eps, state.xwidth, state.internalstate);
        lbl_9:
            if( !autogkinternaliteration(state.internalstate) )
            {
                goto lbl_10;
            }
            
            //
            // Fill State.X, State.XMinusA, State.BMinusX.
            // Latter two are filled correctly even if B<A.
            //
            x = state.internalstate.x;
            t = Math.Pow(x, 1/(1+alpha));
            state.x = a+t;
            if( (double)(s)>(double)(0) )
            {
                state.xminusa = t;
                state.bminusx = b-(a+t);
            }
            else
            {
                state.xminusa = a+t-b;
                state.bminusx = -t;
            }
            state.needf = true;
            state.rstate.stage = 1;
            goto lbl_rcomm;
        lbl_1:
            state.needf = false;
            if( (double)(alpha)!=(double)(0) )
            {
                state.internalstate.f = state.f*Math.Pow(x, -(alpha/(1+alpha)))/(1+alpha);
            }
            else
            {
                state.internalstate.f = state.f;
            }
            state.nfev = state.nfev+1;
            goto lbl_9;
        lbl_10:
            v1 = state.internalstate.r;
            state.nintervals = state.nintervals+state.internalstate.heapused;
            
            //
            // then, integrate right half of [a,b]:
            //     integral(f(x)dx, (b+a)/2, b) =
            //     = 1/(1+beta) * integral(t^(-beta/(1+beta))*f(b-t^(1/(1+beta)))dt, 0, (0.5*(b-a))^(1+beta))
            //
            autogkinternalprepare(0, Math.Pow(0.5*(b-a), 1+beta), eps, state.xwidth, state.internalstate);
        lbl_11:
            if( !autogkinternaliteration(state.internalstate) )
            {
                goto lbl_12;
            }
            
            //
            // Fill State.X, State.XMinusA, State.BMinusX.
            // Latter two are filled correctly (X-A, B-X) even if B<A.
            //
            x = state.internalstate.x;
            t = Math.Pow(x, 1/(1+beta));
            state.x = b-t;
            if( (double)(s)>(double)(0) )
            {
                state.xminusa = b-t-a;
                state.bminusx = t;
            }
            else
            {
                state.xminusa = -t;
                state.bminusx = a-(b-t);
            }
            state.needf = true;
            state.rstate.stage = 2;
            goto lbl_rcomm;
        lbl_2:
            state.needf = false;
            if( (double)(beta)!=(double)(0) )
            {
                state.internalstate.f = state.f*Math.Pow(x, -(beta/(1+beta)))/(1+beta);
            }
            else
            {
                state.internalstate.f = state.f;
            }
            state.nfev = state.nfev+1;
            goto lbl_11;
        lbl_12:
            v2 = state.internalstate.r;
            state.nintervals = state.nintervals+state.internalstate.heapused;
            
            //
            // final result
            //
            state.v = s*(v1+v2);
            state.terminationtype = 1;
            result = false;
            return result;
        lbl_7:
            result = false;
            return result;
            
            //
            // Saving state
            //
        lbl_rcomm:
            result = true;
            state.rstate.ra[0] = s;
            state.rstate.ra[1] = tmp;
            state.rstate.ra[2] = eps;
            state.rstate.ra[3] = a;
            state.rstate.ra[4] = b;
            state.rstate.ra[5] = x;
            state.rstate.ra[6] = t;
            state.rstate.ra[7] = alpha;
            state.rstate.ra[8] = beta;
            state.rstate.ra[9] = v1;
            state.rstate.ra[10] = v2;
            return result;
        }
        /*************************************************************************
        Integration on a finite interval [A,B].
        Integrand have integrable singularities at A/B.

        F(X) must diverge as "(x-A)^alpha" at A, as "(B-x)^beta" at B,  with known
        alpha/beta (alpha>-1, beta>-1).  If alpha/beta  are  not known,  estimates
        from below can be used (but these estimates should be greater than -1 too).

        One  of  alpha/beta variables (or even both alpha/beta) may be equal to 0,
        which means than function F(x) is non-singular at A/B. Anyway (singular at
        bounds or not), function F(x) is supposed to be continuous on (A,B).

        Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
        is calculated with accuracy close to the machine precision.

        INPUT PARAMETERS:
            A, B    -   interval boundaries (A<B, A=B or A>B)
            Alpha   -   power-law coefficient of the F(x) at A,
                        Alpha>-1
            Beta    -   power-law coefficient of the F(x) at B,
                        Beta>-1

        OUTPUT PARAMETERS
            State   -   structure which stores algorithm state between  subsequent
                        calls of AutoGKIteration.  Used for reverse communication.
                        This structure should be  passed  to  the  AutoGKIteration
                        subroutine.

        SEE ALSO
            AutoGKSmooth, AutoGKSmoothW, AutoGKIteration, AutoGKResults.


          -- ALGLIB --
             Copyright 06.05.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void autogksingular(double a,
            double b,
            double alpha,
            double beta,
            ref autogkstate state)
        {
            state.wrappermode = 1;
            state.a = a;
            state.b = b;
            state.alpha = alpha;
            state.beta = beta;
            state.xwidth = 0.0;
            state.rstate.ra = new double[10+1];
            state.rstate.stage = -1;
        }
        /*************************************************************************
        Integration of a smooth function F(x) on a finite interval [a,b].

        This subroutine is same as AutoGKSmooth(), but it guarantees that interval
        [a,b] is partitioned into subintervals which have width at most XWidth.

        Subroutine  can  be  used  when  integrating nearly-constant function with
        narrow "bumps" (about XWidth wide). If "bumps" are too narrow, AutoGKSmooth
        subroutine can overlook them.

        INPUT PARAMETERS:
            A, B    -   interval boundaries (A<B, A=B or A>B)

        OUTPUT PARAMETERS
            State   -   structure which stores algorithm state between  subsequent
                        calls of AutoGKIteration.  Used for reverse communication.
                        This structure should be  passed  to  the  AutoGKIteration
                        subroutine.

        SEE ALSO
            AutoGKSmooth, AutoGKSingular, AutoGKIteration, AutoGKResults.


          -- ALGLIB --
             Copyright 06.05.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void autogksmoothw(double a,
            double b,
            double xwidth,
            ref autogkstate state)
        {
            state.wrappermode = 0;
            state.a = a;
            state.b = b;
            state.xwidth = xwidth;
            state.rstate.ra = new double[10+1];
            state.rstate.stage = -1;
        }
        /*************************************************************************
        Integration of a smooth function F(x) on a finite interval [a,b].

        Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
        is calculated with accuracy close to the machine precision.

        Algorithm works well only with smooth integrands.  It  may  be  used  with
        continuous non-smooth integrands, but with  less  performance.

        It should never be used with integrands which have integrable singularities
        at lower or upper limits - algorithm may crash. Use AutoGKSingular in such
        cases.

        INPUT PARAMETERS:
            A, B    -   interval boundaries (A<B, A=B or A>B)
            
        OUTPUT PARAMETERS
            State   -   structure which stores algorithm state between  subsequent
                        calls of AutoGKIteration.  Used for reverse communication.
                        This structure should be  passed  to  the  AutoGKIteration
                        subroutine.

        SEE ALSO
            AutoGKSmoothW, AutoGKSingular, AutoGKIteration, AutoGKResults.
            

          -- ALGLIB --
             Copyright 06.05.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void autogksmooth(double a,
            double b,
            ref autogkstate state)
        {
            autogksmoothw(a, b, 0.0, ref state);
        }
    /*************************************************************************
    Adaptive integration results

    Called after AutoGKIteration returned False.

    Input parameters:
        State   -   algorithm state (used by AutoGKIteration).

    Output parameters:
        V       -   integral(f(x)dx,a,b)
        Rep     -   optimization report (see AutoGKReport description)

      -- ALGLIB --
         Copyright 14.11.2007 by Bochkanov Sergey
    *************************************************************************/
    public static void autogkresults(autogkstate state, out double v, out autogkreport rep)
    {
        v = 0;
        rep = new autogkreport();
        autogk.autogkresults(state.innerobj, ref v, rep.innerobj);
        return;
    }
    /*************************************************************************
    This function is used to launcn iterations of ODE solver

    It accepts following parameters:
        diff    -   callback which calculates dy/dx for given y and x
        obj     -   optional object which is passed to diff; can be NULL


      -- ALGLIB --
         Copyright 07.05.2009 by Bochkanov Sergey

    *************************************************************************/
    public static void autogkintegrate(autogkstate state, integrator1_func func, object obj)
    {
        if( func==null )
            throw new alglibexception("ALGLIB: error in 'autogkintegrate()' (func is null)");
        while( alglib.autogkiteration(state) )
        {
            if( state.needf )
            {
                func(state.innerobj.x, state.innerobj.xminusa, state.innerobj.bminusx, ref state.innerobj.f, obj);
                continue;
            }
            throw new alglibexception("ALGLIB: unexpected error in 'autogksolve'");
        }
    }
    /*************************************************************************
    This function provides reverse communication interface
    Reverse communication interface is not documented or recommended to use.
    See below for functions which provide better documented API
    *************************************************************************/
    public static bool autogkiteration(autogkstate state)
    {

        bool result = autogk.autogkiteration(state.innerobj);
        return result;
    }
Beispiel #15
0
        /*************************************************************************
        Integration of a smooth function F(x) on a finite interval [a,b].

        This subroutine is same as AutoGKSmooth(), but it guarantees that interval
        [a,b] is partitioned into subintervals which have width at most XWidth.

        Subroutine  can  be  used  when  integrating nearly-constant function with
        narrow "bumps" (about XWidth wide). If "bumps" are too narrow, AutoGKSmooth
        subroutine can overlook them.

        INPUT PARAMETERS:
            A, B    -   interval boundaries (A<B, A=B or A>B)

        OUTPUT PARAMETERS
            State   -   structure which stores algorithm state

        SEE ALSO
            AutoGKSmooth, AutoGKSingular, AutoGKResults.


          -- ALGLIB --
             Copyright 06.05.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void autogksmoothw(double a,
            double b,
            double xwidth,
            autogkstate state)
        {
            alglib.ap.assert(math.isfinite(a), "AutoGKSmoothW: A is not finite!");
            alglib.ap.assert(math.isfinite(b), "AutoGKSmoothW: B is not finite!");
            alglib.ap.assert(math.isfinite(xwidth), "AutoGKSmoothW: XWidth is not finite!");
            state.wrappermode = 0;
            state.a = a;
            state.b = b;
            state.xwidth = xwidth;
            state.needf = false;
            state.rstate.ra = new double[10+1];
            state.rstate.stage = -1;
        }
Beispiel #16
0
        /*************************************************************************
        Integration on a finite interval [A,B].
        Integrand have integrable singularities at A/B.

        F(X) must diverge as "(x-A)^alpha" at A, as "(B-x)^beta" at B,  with known
        alpha/beta (alpha>-1, beta>-1).  If alpha/beta  are  not known,  estimates
        from below can be used (but these estimates should be greater than -1 too).

        One  of  alpha/beta variables (or even both alpha/beta) may be equal to 0,
        which means than function F(x) is non-singular at A/B. Anyway (singular at
        bounds or not), function F(x) is supposed to be continuous on (A,B).

        Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
        is calculated with accuracy close to the machine precision.

        INPUT PARAMETERS:
            A, B    -   interval boundaries (A<B, A=B or A>B)
            Alpha   -   power-law coefficient of the F(x) at A,
                        Alpha>-1
            Beta    -   power-law coefficient of the F(x) at B,
                        Beta>-1

        OUTPUT PARAMETERS
            State   -   structure which stores algorithm state

        SEE ALSO
            AutoGKSmooth, AutoGKSmoothW, AutoGKResults.


          -- ALGLIB --
             Copyright 06.05.2009 by Bochkanov Sergey
        *************************************************************************/
        public static void autogksingular(double a,
            double b,
            double alpha,
            double beta,
            autogkstate state)
        {
            alglib.ap.assert(math.isfinite(a), "AutoGKSingular: A is not finite!");
            alglib.ap.assert(math.isfinite(b), "AutoGKSingular: B is not finite!");
            alglib.ap.assert(math.isfinite(alpha), "AutoGKSingular: Alpha is not finite!");
            alglib.ap.assert(math.isfinite(beta), "AutoGKSingular: Beta is not finite!");
            state.wrappermode = 1;
            state.a = a;
            state.b = b;
            state.alpha = alpha;
            state.beta = beta;
            state.xwidth = 0.0;
            state.needf = false;
            state.rstate.ra = new double[10+1];
            state.rstate.stage = -1;
        }
Beispiel #17
0
 /*************************************************************************
 *  Integration of a smooth function F(x) on a finite interval [a,b].
 *
 *  Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
 *  is calculated with accuracy close to the machine precision.
 *
 *  Algorithm works well only with smooth integrands.  It  may  be  used  with
 *  continuous non-smooth integrands, but with  less  performance.
 *
 *  It should never be used with integrands which have integrable singularities
 *  at lower or upper limits - algorithm may crash. Use AutoGKSingular in such
 *  cases.
 *
 *  INPUT PARAMETERS:
 *   A, B    -   interval boundaries (A<B, A=B or A>B)
 *
 *  OUTPUT PARAMETERS
 *   State   -   structure which stores algorithm state between  subsequent
 *               calls of AutoGKIteration.  Used for reverse communication.
 *               This structure should be  passed  to  the  AutoGKIteration
 *               subroutine.
 *
 *  SEE ALSO
 *   AutoGKSmoothW, AutoGKSingular, AutoGKIteration, AutoGKResults.
 *
 *
 *  -- ALGLIB --
 *    Copyright 06.05.2009 by Bochkanov Sergey
 *************************************************************************/
 public static void autogksmooth(double a,
                                 double b,
                                 ref autogkstate state)
 {
     autogksmoothw(a, b, 0.0, ref state);
 }
Beispiel #18
0
        /*************************************************************************
        Adaptive integration results

        Called after AutoGKIteration returned False.

        Input parameters:
            State   -   algorithm state (used by AutoGKIteration).

        Output parameters:
            V       -   integral(f(x)dx,a,b)
            Rep     -   optimization report (see AutoGKReport description)

          -- ALGLIB --
             Copyright 14.11.2007 by Bochkanov Sergey
        *************************************************************************/
        public static void autogkresults(autogkstate state,
            ref double v,
            autogkreport rep)
        {
            v = 0;

            v = state.v;
            rep.terminationtype = state.terminationtype;
            rep.nfev = state.nfev;
            rep.nintervals = state.nintervals;
        }
    /*************************************************************************
    Integration of a smooth function F(x) on a finite interval [a,b].

    This subroutine is same as AutoGKSmooth(), but it guarantees that interval
    [a,b] is partitioned into subintervals which have width at most XWidth.

    Subroutine  can  be  used  when  integrating nearly-constant function with
    narrow "bumps" (about XWidth wide). If "bumps" are too narrow, AutoGKSmooth
    subroutine can overlook them.

    INPUT PARAMETERS:
        A, B    -   interval boundaries (A<B, A=B or A>B)

    OUTPUT PARAMETERS
        State   -   structure which stores algorithm state

    SEE ALSO
        AutoGKSmooth, AutoGKSingular, AutoGKResults.


      -- ALGLIB --
         Copyright 06.05.2009 by Bochkanov Sergey
    *************************************************************************/
    public static void autogksmoothw(double a, double b, double xwidth, out autogkstate state)
    {
        state = new autogkstate();
        autogk.autogksmoothw(a, b, xwidth, state.innerobj);
        return;
    }