private static void test11() //****************************************************************************80 // // Purpose: // // TEST11 tests MONTE_CARLO. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 19 November 2008 // // Author: // // John Burkardt // { int dim; const int dim_num = 2; int k; Console.WriteLine(""); Console.WriteLine("TEST11"); Console.WriteLine(" MONTE_CARLO applies a Monte Carlo scheme"); Console.WriteLine(" to estimate the integral of a function"); Console.WriteLine(" over the unit hypercube."); Console.WriteLine(""); Console.WriteLine(" The spatial dimension DIM_NUM = " + dim_num + ""); double[] a = new double[dim_num]; double[] b = new double[dim_num]; for (dim = 0; dim < dim_num; dim++) { a[dim] = 0.0; } for (dim = 0; dim < dim_num; dim++) { b[dim] = 1.0; } int seed = 123456789; double exact = FibonacciLattice.e_01_2d(dim_num, a, b); Console.WriteLine(""); Console.WriteLine(" K M EXACT ESTIMATE ERROR"); Console.WriteLine(""); for (k = 2; k <= 5; k++) { int m = (int)Math.Pow(10, k); double quad = MonteCarlo.monte_carlo(dim_num, m, FibonacciLattice.f_01_2d, ref seed); double error = Math.Abs(exact - quad); Console.WriteLine(" " + k.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + m.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + exact.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + error.ToString(CultureInfo.InvariantCulture).PadLeft(10) + ""); } }
private static void test01() //****************************************************************************80 // // Purpose: // // TEST01 tests FIBONACCI_LATTICE_Q. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 19 November 2008 // // Author: // // John Burkardt // { int dim; const int dim_num = 2; int k; Console.WriteLine(""); Console.WriteLine("TEST01"); Console.WriteLine(" FIBONACCI_LATTICE_Q applies a Fibonacci lattice rule"); Console.WriteLine(" to integrate a function over the unit square."); Console.WriteLine(" These Fibonacci rules are only available in 2D."); Console.WriteLine(""); Console.WriteLine(" The spatial dimension DIM_NUM = " + dim_num + ""); double[] a = new double[dim_num]; double[] b = new double[dim_num]; for (dim = 0; dim < dim_num; dim++) { a[dim] = 0.0; } for (dim = 0; dim < dim_num; dim++) { b[dim] = 1.0; } double exact = FibonacciLattice.e_01_2d(dim_num, a, b); Console.WriteLine(""); Console.WriteLine(" K M EXACT ESTIMATE ERROR"); Console.WriteLine(""); for (k = 3; k <= 18; k++) { int m = Helpers.fibonacci(k); double quad = FibonacciLattice.fibonacci_lattice_q(k, FibonacciLattice.f_01_2d); double error = Math.Abs(exact - quad); Console.WriteLine(" " + k.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + m.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + exact.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + error.ToString(CultureInfo.InvariantCulture).PadLeft(10) + ""); } }
private static void test10() //****************************************************************************80 // // Purpose: // // TEST10 tests LATTICE_NP1. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 23 November 2008 // // Author: // // John Burkardt // // Reference: // // Ian Sloan, Stephen Joe, // Lattice Methods for Multiple Integration, // Oxford, 1994, page 18. // { int dim; const int dim_num = 2; int k; Console.WriteLine(""); Console.WriteLine("TEST10"); Console.WriteLine(" LATTICE_NP1 applies a lattice rule to a"); Console.WriteLine(" nonperiodic function using a nonlinear transformation"); Console.WriteLine(" to integrate a function over the unit square."); Console.WriteLine(""); Console.WriteLine(" The spatial dimension DIM_NUM = " + dim_num + ""); int[] z = new int[dim_num]; z[0] = 1; z[1] = 2; double[] a = new double[dim_num]; double[] b = new double[dim_num]; for (dim = 0; dim < dim_num; dim++) { a[dim] = 0.0; } for (dim = 0; dim < dim_num; dim++) { b[dim] = 1.0; } typeMethods.i4vec_print(dim_num, z, " The lattice generator vector:"); Console.WriteLine(""); Console.WriteLine(" I M EXACT ESTIMATE ERROR"); Console.WriteLine(""); for (k = 3; k <= 18; k++) { int m = Helpers.fibonacci(k); double quad = Lattice.lattice_np1(dim_num, m, z, FibonacciLattice.f_01_2d); double exact = FibonacciLattice.e_01_2d(dim_num, a, b); double error = Math.Abs(exact - quad); Console.WriteLine(" " + k.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + m.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + exact.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + error.ToString(CultureInfo.InvariantCulture).PadLeft(10) + ""); } }
private static void test08() //****************************************************************************80 // // Purpose: // // TEST08 tests LATTICE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 21 November 2008 // // Author: // // John Burkardt // // Reference: // // Ian Sloan, Stephen Joe, // Lattice Methods for Multiple Integration, // Oxford, 1994, page 18. // { int dim; const int dim_num = 2; int i; const int m = 53; Console.WriteLine(""); Console.WriteLine("TEST08"); Console.WriteLine(" LATTICE applies a lattice rule to integrate"); Console.WriteLine(" a function over the unit hypercube."); Console.WriteLine(""); Console.WriteLine(" The spatial dimension DIM_NUM = " + dim_num + ""); Console.WriteLine(" The lattice rule order M will vary."); Console.WriteLine(" The lattice generator vector Z will vary."); int[] z = new int[dim_num]; z[0] = 1; double[] a = new double[dim_num]; double[] b = new double[dim_num]; for (dim = 0; dim < dim_num; dim++) { a[dim] = 0.0; } for (dim = 0; dim < dim_num; dim++) { b[dim] = 1.0; } typeMethods.i4vec_print(dim_num, z, " The lattice generator vector:"); Console.WriteLine(""); Console.WriteLine(" M Z[0] Z[1] EXACT ESTIMATE ERROR"); Console.WriteLine(""); for (i = 1; i <= m - 1; i++) { z[1] = i; double quad = Lattice.lattice(dim_num, m, z, FibonacciLattice.f_01_2d); double exact = FibonacciLattice.e_01_2d(dim_num, a, b); double error = Math.Abs(exact - quad); Console.WriteLine(" " + m.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + z[0].ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + z[1].ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + exact.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + error.ToString(CultureInfo.InvariantCulture).PadLeft(10) + ""); } }