コード例 #1
0
        public void ODEExplicitRungeKutta45()
        {
            //Arenstorf orbit
            //The Arenstorf orbits are closed trajectories of the restricted three-body problem.
            //Two bodies of masses m and (1-m) moving in a circular rotation, and a third body of
            //negligible mass moving in the same plane (such as a satellite-earth-moon system.)

            //using DotNumerics.ODE

            OdeFunction             fun  = new OdeFunction(ArenstorfOrbit);
            OdeExplicitRungeKutta45 RK45 = new OdeExplicitRungeKutta45(fun, 4);

            RK45.RelTol = 1.0E-7;
            RK45.AbsTol = 1.0E-7;

            double x0 = 0;

            double[] y0 = new double[4];
            y0[0] = 0.994E0;
            y0[1] = 0.0E0;
            y0[2] = 0.0E0;
            y0[3] = -2.00158510637908252240537862224E0;

            RK45.SetInitialValues(x0, y0);

            double[,] y;
            double[] x = new double[10];
            for (int i = 0; i < 10; i++)
            {
                x[i] = 2 * i;
            }

            y = RK45.Solve(y0, x);

            for (int i = 0; i < 10; i++)
            {
                ObjectDumper.Write("X = " + x[i].ToString() + "  Y1 = " + y[i, 1].ToString() + " Y2 = " + y[i, 2].ToString());
            }

            //private double[] ArenstorfOrbit(double t, double[] y)
            //{
            //    double[] ydot = new double[4];
            //    double amu = 0; double amup = 0; double r1 = 0; double r2 = 0;
            //    double a = 0.012277471E0;
            //    double b = 1 - a;
            //    amu = a;
            //    amup = b;
            //    ydot[0] = y[2];
            //    ydot[1] = y[3];
            //    r1 = Math.Pow(y[0] + amu, 2) + Math.Pow(y[1], 2);
            //    r1 *= Math.Sqrt(r1);
            //    r2 = Math.Pow(y[0] - amup, 2) + Math.Pow(y[1], 2);
            //    r2 *= Math.Sqrt(r2);
            //    ydot[2] = y[0] + 2 * y[3] - amup * (y[0] + amu) / r1 - amu * (y[0] - amup) / r2;
            //    ydot[3] = y[1] - 2 * y[2] - amup * y[1] / r1 - amu * y[1] / r2;
            //    return ydot;
            //}
        }
コード例 #2
0
        public double[,] Ode(double[] y0, double[] x)
        {
            OdeExplicitRungeKutta45 RK45 = new OdeExplicitRungeKutta45(Simulate, 12)
            {
                RelTol = 0.000001,
                AbsTol = 0.000001
            };

            return(RK45.Solve(y0, x));
        }