コード例 #1
0
        public static double[] ALegendFnmTest(int n, double x)
        {
            double[] Pnm  = new double[n + 1];
            double[] ALFS = new double[n + 1];
            double[] BLFS = new double[n + 1];

            double s = Math.Sqrt(1.0 - x * x);

            switch (n)
            {
            case 0:
                Pnm[0] = 1.0;
                break;

            case 1:
                Pnm[0] = x;
                Pnm[1] = s;
                break;

            default:
                ALFS[0] = (3.0 * x * x - 1.0) / 2.0;
                ALFS[1] = 3.0 * s * x;
                ALFS[2] = 3.0 * (1.0 - x * x);

                if (n == 2)
                {
                    Pnm = ALFS;
                }
                else
                {
                    BLFS[0] = x;
                    BLFS[1] = s;

                    int l = 2;
                    while (l < n)
                    {
                        Pnm[0] = Legendre.LegendreF(l + 1, x);
                        int k = 1;
                        while (k <= l + 1)
                        {
                            if (k <= l - 1)
                            {
                                Pnm[k] = ((2 * l + 1) * x * ALFS[k] - (l + k) * BLFS[k]) / (l - k + 1);
                            }

                            else if (k > l - 1)
                            {
                                Pnm[k] = -((l - k + 2) * x * Pnm[k - 1] - (l + k) * ALFS[k - 1]) / s;
                            }
                            k = k + 1;
                        }
                        Array.Copy(ALFS, BLFS, ALFS.Length);
                        Array.Copy(Pnm, ALFS, Pnm.Length);
                        l = l + 1;
                    }
                }
                break;
            }
            return(Pnm);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            double normal_g  = 0.0;
            double adopted_g = 0.0;
            double calc_g0   = 0.0;
            double calc_g1   = 0.0;

            Console.WriteLine();
            Console.WriteLine("           normal        Adopted         Calculated        Calculated ");
            Console.WriteLine("phi        gravity       Gravity          gravity0          gravity1 ");
            for (double ph = 0; ph <= 90; ph = ph + 5.0)
            {
                normal_g  = Legendre.normalGravity(ph) * 1e5;
                adopted_g = Legendre.adaptedGravity(ph, 0.0) * 1e5;
                calc_g0   = Legendre.Calcgravity(ph, 0) * 1e5;
                calc_g1   = Legendre.Calcgravity(ph, 1) * 1e5;
                Console.WriteLine("{0:0.0}    {1:0.000000}    {2:0.000000}    {3:0.000000}    {4:0.000000}",
                                  ph, normal_g, adopted_g, calc_g0, calc_g1);
            }

            /*
             * string fileName = @"file directory\dV_ELL_Earth2014.gfc";
             *     if (File.Exists(fileName))
             *     {
             *         double Phi = 45.0;
             *         double[] Lambda = { 46.0, 47.0, 48.0 };
             *         for(int i=0; i<=2; i++)
             *         {
             *             Console.WriteLine();
             *             double del_g = Legendre.gravitation(Phi, Lambda[i], 0, fileName);
             *             double calc_g = Legendre.Calcgravity(Phi, 1);
             *             Console.WriteLine(" Delta_Gravity at Latitude {0} , Longitude {1} is {2}",
             *                 Phi, Lambda[i], del_g);
             *             double g = (calc_g + del_g) * 1E5;
             *             Console.WriteLine(" Calculated Gravity at Latitude {0} , Longitude {1} is {2}",
             *                 Phi, Lambda[i], g);
             *         }
             *
             *     }
             *     else
             *     {
             *         Console.WriteLine("File Does Not Exists");
             *     }
             */
        }
コード例 #3
0
        public static double[] ALegendFnmSeri(int n, double x)
        {
            double[] Pnm  = new double[n + 1];
            double[] ALFS = new double[n + 1];
            double[] BLFS = new double[n + 1];

            double s = Math.Sqrt(1.0 - x * x);

            switch (n)
            {
            case 0:
                Pnm[0] = 1.0;
                break;

            case 1:
                Pnm[0] = x;
                Pnm[1] = s;
                break;

            case 2:
                Pnm[0] = (3.0 * x * x - 1.0) / 2.0;
                Pnm[1] = 3.0 * s * x;
                Pnm[2] = 3.0 * (1.0 - x * x);
                break;

            case 3:
                Pnm[0] = x * (5.0 * x * x - 3.0) / 2.0;
                Pnm[1] = 3.0 * (5.0 * x * x - 1.0) * s / 2.0;
                Pnm[2] = 15.0 * x * (1.0 - x * x);
                Pnm[3] = 15.0 * s * s * s;
                break;

            case 4:
                Pnm[0] = (35.0 * x * x * x * x - 30.0 * x * x + 3.0) / 8.0;
                Pnm[1] = 5.0 * (7.0 * x * x - 3.0) * x * s / 2.0;
                Pnm[2] = 15.0 * (7.0 * x * x - 1.0) * (1.0 - x * x) / 2.0;
                Pnm[3] = 105.0 * s * s * s * x;
                Pnm[4] = 105.0 * s * s * s * s;
                break;

            case 5:
                Pnm[0] = x * (63.0 * x * x * x * x - 70.0 * x * x + 15.0) / 8.0;
                Pnm[1] = 15.0 * s * (21.0 * x * x * x * x - 14.0 * x * x + 1.0) / 8.0;
                Pnm[2] = 105.0 * x * (3.0 * x * x - 1.0) * (1.0 - x * x) / 2.0;
                Pnm[3] = 105.0 * s * s * s * (9.0 * x * x - 1.0) / 2.0;
                Pnm[4] = 945.0 * s * s * s * s * x;
                Pnm[5] = 945.0 * s * s * s * s * s;
                break;

            case 6:
                Pnm[0] = (x * x * (x * x * (231.0 * x * x - 315.0) + 105.0) - 5.0) / 16.0;
                Pnm[1] = 21.0 * x * (x * x * (33.0 * x * x - 30.0) + 5.0) * s / 8.0;
                Pnm[2] = 105.0 * s * s * (x * x * (33.0 * x * x - 18.0) + 1.0) / 8.0;
                Pnm[3] = 315.0 * (11.0 * x * x - 3.0) * x * s * s * s / 2.0;
                Pnm[4] = 945.0 * s * s * s * s * (11.0 * x * x - 1.0) / 2.0;
                Pnm[5] = 10395.0 * x * s * s * s * s * s;
                Pnm[6] = 10395.0 * s * s * s * s * s * s;
                break;

            case 7:
                Pnm[0] = x * (x * x * (429.0 * Math.Pow(x, 4) - 693.0 * x * x + 315.0) - 35.0) / 16.0;
                Pnm[1] = 7.0 * s * (x * x * (429.0 * Math.Pow(x, 4) - 495.0 * x * x + 135.0) - 5.0) / 16.0;
                Pnm[2] = 63.0 * x * s * s * (x * x * (143.0 * x * x - 110.0) + 15.0) / 8.0;
                Pnm[3] = 315.0 * s * s * s * (x * x * (143.0 * x * x - 66.0) + 3.0) / 8.0;
                Pnm[4] = 3465.0 * x * s * s * s * s * (13.0 * x * x - 3.0) / 2.0;
                Pnm[5] = 10395.0 * Math.Pow(s, 5) * (13.0 * x * x - 1.0) / 2.0;
                Pnm[6] = 135135.0 * x * Math.Pow(s, 6);
                Pnm[7] = 135135.0 * Math.Pow(s, 7);
                break;

            default:
                ALFS[0] = (x * x * (x * x * (x * x * (6435.0 * x * x - 12012.0) + 6930.0) - 1260.0) + 35) / 128.0;
                ALFS[1] = 9.0 * x * s * (x * x * (x * x * (715.0 * x * x - 1001.0) + 385.0) - 35.0) / 16.0;
                ALFS[2] = 315.0 * s * s * (x * x * (x * x * (143.0 * x * x - 143.0) + 33.0) - 1.0) / 16.0;
                ALFS[3] = 3465.0 * x * s * s * s * (x * x * (39.0 * x * x - 26.0) + 3.0) / 8.0;
                ALFS[4] = 10395.0 * s * s * s * s * (65.0 * Math.Pow(x, 4) - 26.0 * x * x + 1.0) / 8.0;
                ALFS[5] = 135135.0 * x * Math.Pow(s, 5) * (5.0 * x * x - 1.0) / 2.0;
                ALFS[6] = 135135.0 * Math.Pow(s, 6) * (15.0 * x * x - 1.0) / 2.0;
                ALFS[7] = 2027025.0 * x * s * s * s * s * s * s * s;
                ALFS[8] = 2027025.0 * s * s * s * s * s * s * s * s;

                if (n == 8)
                {
                    Pnm = ALFS;
                }
                else
                {
                    BLFS[0] = x * (x * x * (429.0 * Math.Pow(x, 4) - 693.0 * x * x + 315.0) - 35.0) / 16.0;
                    BLFS[1] = 7.0 * s * (x * x * (429.0 * Math.Pow(x, 4) - 495.0 * x * x + 135.0) - 5.0) / 16.0;
                    BLFS[2] = 63.0 * x * s * s * (x * x * (143.0 * x * x - 110.0) + 15.0) / 8.0;
                    BLFS[3] = 315.0 * s * s * s * (x * x * (143.0 * x * x - 66.0) + 3.0) / 8.0;
                    BLFS[4] = 3465.0 * x * s * s * s * s * (13.0 * x * x - 3.0) / 2.0;
                    BLFS[5] = 10395.0 * Math.Pow(s, 5) * (13.0 * x * x - 1.0) / 2.0;
                    BLFS[6] = 135135.0 * x * Math.Pow(s, 6);
                    BLFS[7] = 135135.0 * Math.Pow(s, 7);

                    int l = 8;
                    while (l < n)
                    {
                        Pnm[0] = Legendre.LegendreF(l + 1, x);
                        int k = 1;
                        while (k <= l + 1)
                        {
                            if (k <= l - 1)
                            {
                                Pnm[k] = ((2 * l + 1) * x * ALFS[k] - (l + k) * BLFS[k]) / (l - k + 1);
                            }

                            else if (k > l - 1)
                            {
                                Pnm[k] = -((l - k + 2) * x * Pnm[k - 1] - (l + k) * ALFS[k - 1]) / s;
                            }
                            k = k + 1;
                        }
                        Array.Copy(ALFS, BLFS, ALFS.Length);
                        Array.Copy(Pnm, ALFS, Pnm.Length);
                        l = l + 1;
                    }
                }
                break;
            }
            return(Pnm);
        }