Exemplo n.º 1
0
        public static ValueAndArgumentVector nextStep(double h, List<ValueAndArgumentVector> preSteps, Func<double, double[], double[]> f)
        {
            ValueAndArgumentVector result = new ValueAndArgumentVector();
            int li = preSteps.Count - 1;
            int li1 = li - 1;
            int li2 = li - 2;
            result.x = preSteps[li].x + h;
            for(int i = 0; i < preSteps[0].y.Length; i++)
            {
                result.y[i] = preSteps[li].y[i] + h * (double)1 / 3 * (5.75 * f(preSteps[li].x, preSteps[li].y)[i] - 4 * f(preSteps[li1].x, preSteps[li1].y)[i] + 1.25 * f(preSteps[li2].x, preSteps[li2].y)[i]);
            }

            result.N = preSteps[li].N + 1;
            return result;
        }
Exemplo n.º 2
0
        public static ValueAndArgumentVector nextStep(double h, ValueAndArgumentVector prev, Func<double, double[], double[]> f)
        {
            ValueAndArgumentVector result = new ValueAndArgumentVector();
            result.x = prev.x + h;
            result.N = prev.N + 1;
            double[] k1 = new double[prev.y.Length];
            double[] k2 = new double[prev.y.Length];
            double[] k3 = new double[prev.y.Length];
            double[] k4 = new double[prev.y.Length];

            for (int i = 0; i < prev.y.Length; i++)
            {
                k1[i] = f(prev.x, prev.y)[i];
            }
            for (int i = 0; i < prev.y.Length; i++)
            {
                double[] yi = new double[prev.y.Length];
                for(int j = 0; j < prev.y.Length; j++)
                {
                    yi[i] = prev.y[i] + h / 2 * k1[i];
                }
                k2[i] = f(prev.x + h / 2, yi)[i];
            }
            for (int i = 0; i < prev.y.Length; i++)
            {
                double[] yi = new double[prev.y.Length];
                for (int j = 0; j < prev.y.Length; j++)
                {
                    yi[i] = prev.y[i] + h / 2 * k2[i];
                }
                k3[i] = f(prev.x + h / 2, yi)[i];
            }
            for (int i = 0; i < prev.y.Length; i++)
            {
                double[] yi = new double[prev.y.Length];
                for (int j = 0; j < prev.y.Length; j++)
                {
                    yi[i] = prev.y[i] + h * k3[i];
                }
                k4[i] = f(prev.x + h, yi)[i];
            }
            for (int i = 0; i < prev.y.Length; i++)
            {
                result.y[i] = prev.y[i] + h / 6 * (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]);
            }
            return result;
        }