Пример #1
0
        private static double EvtWrapper(EvtFun f, double newh, double x1, ReadOnlySpan <double> y1, ReadOnlySpan <double> yp1, double x2, ReadOnlySpan <double> y2, ReadOnlySpan <double> yp2, int n, object o)
        {
            Span <double> newy = stackalloc double[n];

            ODE.CubicHermiteInterpolant(x1, y1, yp1, x2, y2, yp2, x1 + newh, n, newy);
            return(f(newy, x1 + newh, n, o));
        }
Пример #2
0
        static void Main(string[] args)
        {
            double[] y0  = { 1, 0, 0, 0, 1, 0 };
            double[] x   = { 0 * 0.78539816339, 1 * 0.78539816339, 2 * 0.78539816339, 3 * 0.78539816339, 4 * 0.78539816339 };
            ODE      ode = new ODE(y0, 6, x, 1e-9, 0, allvals: true);

            ode.RKF45(centralForce, null);
            for (int i = 0; i < ode.xlist.Count; i++)
            {
                Console.Write(ode.xlist[i]);
                if (i != ode.xlist.Count - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.Write("\n");
            for (int i = 0; i < ode.ylist.Count; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    Console.Write(ode.ylist[i][j]);
                    if (j != 5)
                    {
                        Console.Write(", ");
                    }
                }
                Console.Write("\n");
            }
        }
Пример #3
0
        static void Main2(string[] args)
        {
            List <double []> ylist = new List <double []>();
            List <double>    xlist = new List <double>();

            double[]   y0 = { 1, 0, 0, 0, 1, 0 };
            double[]   x  = { 0 * 0.78539816339, 1 * 0.78539816339, 2 * 0.78539816339, 3 * 0.78539816339, 4 * 0.78539816339 };
            double[][] y  = new double[][]
            {
                new double[5],
                new double[5],
                new double[5],
                new double[5],
                new double[5],
                new double[5],
            };

            var watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < 100000; i++)
            {
                ODE.RKDP547FM(centralForce, null, y0, 6, x, y, 1e-9, 0, xlist: xlist, ylist: ylist);
            }
            watch.Stop();
            Console.WriteLine("ms : {0:F6}", watch.ElapsedMilliseconds);
            for (int i = 0; i < xlist.Count; i++)
            {
                Console.Write(xlist[i]);
                if (i != xlist.Count - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.Write("\n");
            for (int i = 0; i < ylist.Count; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    Console.Write(ylist[i][j]);
                    if (j != 5)
                    {
                        Console.Write(", ");
                    }
                }
                Console.Write("\n");
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            List <double []> ylist = new List <double []>();
            List <double>    xlist = new List <double>();

            double[]   y0 = { 0, 20 };
            double[]   x  = { 0, 5 };
            double[][] y  = new double[][]
            {
                new double[2],
                new double[2],
            };
            EvtFun[] EvtFuns = { ballevent };
            ODE.RKDP547FM(ball, null, y0, 2, x, y, 1e-9, 0, hmin: 1e-8, xlist: xlist, ylist: ylist, EvtFuns: EvtFuns);
            for (int i = 0; i < xlist.Count; i++)
            {
                Console.Write(xlist[i]);
                if (i != xlist.Count - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.Write("\n");
            for (int i = 0; i < ylist.Count; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Console.Write(ylist[i][j]);
                    if (j != 1)
                    {
                        Console.Write(", ");
                    }
                }
                Console.Write("\n");
            }
        }