Пример #1
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests the coordinate conversion routines.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    15 December 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int m;

        Console.WriteLine("");
        Console.WriteLine("TEST01");
        Console.WriteLine("  Test the coordinate conversion routines:");
        Console.WriteLine("  CARTESIAN_TO_HYPERSPHERE: X       -> R,Theta");
        Console.WriteLine("  HYPERSPHERE_TO_CARTESIAN: R,Theta -> X.");
        Console.WriteLine("");
        Console.WriteLine("  Pick a random X, and compute X2 by converting X");
        Console.WriteLine("  to hypersphere and back.  Consider norm of difference.");
        Console.WriteLine("");
        Console.WriteLine("  M    || X - X2 ||");

        int seed = 123456789;

        const int n = 1;

        double[] r = new double[n];

        for (m = 1; m <= 5; m++)
        {
            Console.WriteLine("");

            double[] theta = new double[(m - 1) * n];

            int test;
            for (test = 1; test <= 5; test++)
            {
                double[] x = UniformRNG.r8mat_uniform_01_new(m, n, ref seed);
                double[] c = UniformRNG.r8vec_uniform_01_new(m, ref seed);
                Hypersphere.cartesian_to_hypersphere(m, n, c, x, ref r, ref theta);
                double[] x2  = Hypersphere.hypersphere_to_cartesian(m, n, c, r, theta);
                double   err = typeMethods.r8mat_norm_fro_affine(m, n, x, x2);
                Console.WriteLine("  " + m.ToString(CultureInfo.InvariantCulture).PadLeft(2)
                                  + "  " + err.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
            }
        }
    }