Beispiel #1
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TOMS243_TEST tests TOMS243.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    04 January 2019
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        Complex fx1 = new(0, 0);
        Complex x   = new(0, 0);

        Console.WriteLine("");
        Console.WriteLine("TOMS243_TEST:");
        Console.WriteLine("  TOMS243 computes the natural logarithm of a complex value.");
        Console.WriteLine("");
        Console.WriteLine("               X                               FX exact");
        Console.WriteLine("                                               FX computed");
        Console.WriteLine("");

        int n_data = 0;

        while (true)
        {
            Cmplex.c8_log_values(ref n_data, ref x, ref fx1);

            if (n_data == 0)
            {
                break;
            }

            Complex fx2 = TOMS.toms243(x);

            Console.WriteLine("  ( "
                              + x.Real.ToString("0.####").PadLeft(8) + ","
                              + x.Imaginary.ToString("0.####").PadLeft(8) + ")  ( "
                              + fx1.Real.ToString("0.############").PadLeft(18) + ","
                              + fx1.Imaginary.ToString("0.############").PadLeft(18) + ")");
            Console.WriteLine("                        ( "
                              + fx2.Real.ToString("0.############").PadLeft(18) + ","
                              + fx2.Imaginary.ToString("0.############").PadLeft(18) + ")");
        }

        Console.WriteLine("");
        Console.WriteLine("TOMS243_TEST:");
        Console.WriteLine("  Normal end of execution:");
        Console.WriteLine("");
    }
Beispiel #2
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 demonstrates the use of MDBETA.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    30 January 2008
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx  = 0;
        int    ier = 0;
        double p   = 0;
        double q   = 0;
        double x   = 0;

        Console.WriteLine("");
        Console.WriteLine("TEST02:");
        Console.WriteLine("  MDBETA estimates the value of th modified Beta function.");
        Console.WriteLine("  Compare with tabulated values.");
        Console.WriteLine("");
        Console.WriteLine("         X         P         Q         "
                          + "Beta                       Beta                  DIFF");
        Console.WriteLine("                                       "
                          + "(Tabulated)                (MDBETA)");
        Console.WriteLine("");

        int n_data = 0;

        for (;;)
        {
            Beta.beta_cdf_values(ref n_data, ref p, ref q, ref x, ref fx);

            if (n_data == 0)
            {
                break;
            }

            double fx2 = TOMS.mdbeta(x, p, q, ref ier);

            Console.WriteLine("  " + x.ToString("0.####").PadLeft(8)
                              + "  " + p.ToString("0.####").PadLeft(8)
                              + "  " + q.ToString("0.####").PadLeft(8)
                              + "  " + fx.ToString("0.################").PadLeft(24)
                              + "  " + fx2.ToString("0.################").PadLeft(24)
                              + "  " + Math.Abs(fx - fx2).ToString("0.####").PadLeft(10) + "");
        }
    }
Beispiel #3
0
    private static void test01()

        //****************************************************************************80
        //
        //  Purpose:
        //
        //    TEST01 tests HOOKE with the Rosenbrock function.
        //
        //  Licensing:
        //
        //    This code is distributed under the GNU LGPL license.
        //
        //  Modified:
        //
        //    12 February 2008
        //
        //  Author:
        //
        //    John Burkardt
        //
    {
        int i;
        const int nvars = 2;

        double[] endpt = new double[nvars];
        double[] startpt = new double[nvars];

        Console.WriteLine("");
        Console.WriteLine("TEST01");
        Console.WriteLine("  HOOKE seeks a minimizer of F(X).");
        Console.WriteLine("  Here we use the Rosenbrock function.");
        //
        //  Starting guess for Rosenbrock.
        //
        startpt[0] = -1.2;
        startpt[1] = 1.0;

        Console.WriteLine("");
        Console.WriteLine("  Initial estimate X =");
        Console.WriteLine("");
        for (i = 0; i < nvars; i++)
        {
            Console.WriteLine("  " + (i + 1).ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                   + "  " + startpt[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        double value = rosenbrock(startpt, nvars);

        Console.WriteLine("");
        Console.WriteLine("  F(X) = " + value + "");
        //
        //  Call HOOKE.
        //
        int itermax = 5000;
        double rho = 0.5;
        double eps = 1.0E-06;

        int it = TOMS.hooke(nvars, startpt, ref endpt, rho, eps, itermax, rosenbrock);
        //
        //  Results.
        //
        Console.WriteLine("");
        Console.WriteLine("  Number of iterations taken = " + it + "");
        Console.WriteLine("");
        Console.WriteLine("  X* = ");
        Console.WriteLine("");
        for (i = 0; i < nvars; i++)
        {
            Console.WriteLine("  " + (i + 1).ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                   + "  " + endpt[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        value = rosenbrock(endpt, nvars);

        Console.WriteLine("");
        Console.WriteLine("  F(X*) = " + value + "");
    }
Beispiel #4
0
    private static void test02()

        //****************************************************************************80
        //
        //  Purpose:
        //
        //    TEST02 tests HOOKE with the WOODS function.
        //
        //  Discussion:
        //
        //    The Hooke and Jeeves algorithm works well when RHO = 0.5, but
        //    does poorly when RHO = 0.6, and better when RHO = 0.8
        //
        //  Licensing:
        //
        //    This code is distributed under the GNU LGPL license.
        //
        //  Modified:
        //
        //    12 February 2008
        //
        //  Author:
        //
        //    John Burkardt
        //
    {
        int i;
        const int nvars = 4;

        double[] endpt = new double[nvars];
        double[] startpt = new double[nvars];

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  HOOKE seeks a minimizer of F(X).");
        Console.WriteLine("  Here we use the Rosenbrock function.");
        Console.WriteLine("  Here we use the Woods function.");
        //
        //  Starting guess.
        //
        startpt[0] = -3.0;
        startpt[1] = -1.0;
        startpt[2] = -3.0;
        startpt[3] = -1.0;

        Console.WriteLine("");
        Console.WriteLine("  Initial estimate X =");
        Console.WriteLine("");
        for (i = 0; i < nvars; i++)
        {
            Console.WriteLine("  " + (i + 1).ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                   + "  " + startpt[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        double value = woods(startpt, nvars);

        Console.WriteLine("");
        Console.WriteLine("  F(X) = " + value + "");
        //
        //  Call HOOKE.
        //
        int itermax = 5000;
        double rho = 0.5;
        double eps = 1.0E-06;

        int it = TOMS.hooke(nvars, startpt, ref endpt, rho, eps, itermax, woods);
        //
        //  Results.
        //
        Console.WriteLine("");
        Console.WriteLine("  Number of iterations taken = " + it + "");
        Console.WriteLine("");
        Console.WriteLine("  X* = ");
        Console.WriteLine("");
        for (i = 0; i < nvars; i++)
        {
            Console.WriteLine("  " + (i + 1).ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                   + "  " + endpt[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        value = woods(endpt, nvars);

        Console.WriteLine("");
        Console.WriteLine("  F(X*) = " + value + "");

    }
Beispiel #5
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for TOMS112_TEST.
    //
    //  Discussion:
    //
    //    TOMS112_TEST tests the TOMS112 library.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    30 November 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int n = 5;
        int       test;
        const int test_num = 4;

        double[] x       = { 0.0, 1.0, 2.0, 1.0, 0.0 };
        double[] x0_test = { 1.0, 3.0, 0.0, 0.5 };
        double[] y       = { 0.0, 0.0, 1.0, 2.0, 2.0 };
        double[] y0_test = { 1.0, 4.0, 2.0, -0.25 };

        Console.WriteLine("");
        Console.WriteLine("TOMS112_TEST");
        Console.WriteLine("  POINT_IN_POLYGON determines if a point is in a polygon.");

        typeMethods.r8vec2_print(n, x, y, "  The polygon vertices:");

        Console.WriteLine("");
        Console.WriteLine("        Px        Py  Inside");
        Console.WriteLine("");

        for (test = 0; test < test_num; test++)
        {
            double x0 = x0_test[test];
            double y0 = y0_test[test];

            bool inside = TOMS.point_in_polygon(n, x, y, x0, y0);

            Console.WriteLine("  " + x0.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + y0.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "       " + inside + "");
        }
        //
        //  Terminate.
        //
        Console.WriteLine("");
        Console.WriteLine("TOMS112_TEST");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }