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 + ""); }
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 + ""); }