Esempio n. 1
0
        public static (double Y, double Error, int Iterations) Step2(
            Func <double, double, double> f,
            double t, double dt,
            double y, double YPrev1, double YPrev2,
            double Eps, int IterationsCount)
        {
            double y1 = AdamsBashforth.Step2(f, t, dt, y, YPrev1, YPrev2), y2, delta;
            var    t1  = t + dt;
            var    t_1 = t - dt;
            var    t_2 = t - 2 * dt;

            var i = 0;

            do
            {
                y2 = y + dt * (
                    9 / 24d * f(t1, y1) +
                    19 / 24d * f(t, y) -
                    5 / 24d * f(t_1, YPrev1) +
                    24 / 24d * f(t_2, YPrev2));
                delta = y2 - y1;
                y1    = y2;
            }while (Abs(delta) > Eps && i++ < IterationsCount);

            return(y2, delta, i);
        }
Esempio n. 2
0
        public static (double Y, double Error, int Iterations) Step3(
            Func <double, double, double> f,
            double t, double dt,
            double y, double YPrev1, double YPrev2, double YPrev3,
            double Eps, int IterationsCount)
        {
            double y1 = AdamsBashforth.Step3(f, t, dt, y, YPrev1, YPrev2, YPrev3), y2, delta;
            var    t1  = t + dt;
            var    t_1 = t - dt;
            var    t_2 = t - 2 * dt;
            var    t_3 = t - 3 * dt;

            var i = 0;

            do
            {
                y2 = y + dt * (
                    251 / 720d * f(t1, y1) +
                    646 / 720d * f(t, y) -
                    264 / 720d * f(t_1, YPrev1) +
                    106 / 720d * f(t_2, YPrev2) -
                    19 / 720d * f(t_3, YPrev3));
                delta = y2 - y1;
                y1    = y2;
            }while (Abs(delta) > Eps && i++ < IterationsCount);

            return(y2, delta, i);
        }
Esempio n. 3
0
        public static (double Y, double Error, int Iterations) Step0(
            Func <double, double, double> f,
            double t, double dt,
            double y,
            double Eps, int IterationsCount)
        {
            double y1 = AdamsBashforth.Step0(f, t, dt, y), y2, delta;
            var    t1 = t + dt;

            var i = 0;

            do
            {
                y2 = y + dt * (
                    0.5 * f(t1, y1) +
                    0.5 * f(t, y));
                delta = y2 - y1;
                y1    = y2;
            }while (Abs(delta) > Eps && i++ < IterationsCount);

            return(y2, delta, i);
        }