コード例 #1
0
        // Core integrator for DOP853
        public double Integrate(ref double t, ref double dt, double[] x, ref int step, int nmax, double posneg, bool dense)
        {
            double th = t, err = 0;

            // Basic integration step
            while (step < nmax)
            {
                Step(t, dt, x);

                step++;

                th = t + dt;

                // Error estimation
                err = Error(dt, x);

                dtold = dt;
                told  = t;

                // Computation of HNEW
                if (controller.Success(err, posneg, ref dt))
                {
                    break;
                }
            }

            fcn(th, xout, k4);

            // Stiffness detection
            if (!stiff.Check(controller.Accepted, dtold, k4, k3, xout, xtemp))
            {
                throw new Exception(" The problem seems to become stiff at t = " + t);
            }

            if (dense)
            {
                PrepareInterpolation(t, dtold, x);
            }

            for (int i = 0; i < n; ++i)
            {
                dxdt[i] = k4[i];
                x[i]    = xout[i];
            }

            t = th;

            return(err);
        }