Example #1
0
    private static void test06()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST06 tests FILON_FUN_COS.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    20 May 2014
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int j;

        //
        //  Example suggested by James Roedder.
        //
        Console.WriteLine("");
        Console.WriteLine("TEST06");
        Console.WriteLine("  Integrate F(X)=log(1+X)*Math.Sin(T*X):");
        Console.WriteLine("  Supply integrand as a function.");
        Console.WriteLine("  T = 10, and N increases");
        Console.WriteLine("");
        Console.WriteLine("       N    Approximate             Exact                   Error");
        Console.WriteLine("");

        double a = 0.0;
        double b = 2.0 * Math.PI;

        for (j = 1; j <= 6; j++)
        {
            int n = (int)Math.Pow(2, j) * 10 + 1;

            double t = 10.0;

            double result = Filon.filon_fun_sin(n, log_integrand, a, b, t);

            double exact = -0.19762680771872;
            double error = result - exact;

            Console.WriteLine(n.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + result.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "  "
                              + exact.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "  "
                              + error.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "");
        }
    }
Example #2
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests FILON_TAB_COS.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    20 May 2014
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double exact = 0;

        double[] ftab = new double[1];
        int      i;
        int      k;
        double   t = 0;

        const double a = 0.0;
        const double b = 2.0 * Math.PI;

        int n = 11;

        //
        //  Set the X values.
        //
        double[] x = new double[n];
        for (i = 0; i < n; i++)
        {
            x[i] = ((n - i - 1) * a
                    + i * b)
                   / (n - 1);
        }

        Console.WriteLine("");
        Console.WriteLine("TEST01");
        Console.WriteLine("  FILON_TAB_COS estimates the integral of.");
        Console.WriteLine("  F(X) * COS ( T * X )");
        Console.WriteLine("  Use integrands F(X)=1, X, X^2.");
        Console.WriteLine("");
        Console.WriteLine("  A = " + a + "");
        Console.WriteLine("  B = " + b + "");
        Console.WriteLine("  N = " + n + "");
        Console.WriteLine("");
        Console.WriteLine("       T                      Approximate             Exact");

        for (k = 1; k <= 3; k++)
        {
            t = k switch
            {
                1 => 1.0,
                2 => 2.0,
                3 => 10.0,
                _ => t
            };

            Console.WriteLine("");

            for (i = 1; i <= 3; i++)
            {
                ftab = i switch
                {
                    1 => zero_integrand(n, x),
                    2 => one_integrand(n, x),
                    3 => two_integrand(n, x),
                    _ => ftab
                };

                double result = Filon.filon_tab_cos(n, ftab, a, b, t);

                exact = i switch
                {
                    1 => (Math.Sin(t * b) - Math.Sin(t * a)) / t,
                    2 => (Math.Cos(t * b) + t * b * Math.Sin(t * b) - (Math.Cos(t * a) + t * a * Math.Sin(t * a))) / t /
                    t,
                    3 => (2.0 * t * b * Math.Cos(t * b) + (t * t * b * b - 2.0) * Math.Sin(t * b) -
                          (2.0 * t * a * Math.Cos(t * a) + (t * t * a * a - 2.0) * Math.Sin(t * a))) / t / t / t,
                    _ => exact
                };

                Console.WriteLine(t.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "  "
                                  + result.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "  "
                                  + exact.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "");
            }
        }
    }
Example #3
0
    private static void test05()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST05 tests FILON_TAB_COS.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    20 May 2014
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int j;

        //
        //  Example suggested by James Roedder.
        //
        Console.WriteLine("");
        Console.WriteLine("TEST05");
        Console.WriteLine("  Integrate F(X)=log(1+X)*Math.Sin(T*X):");
        Console.WriteLine("  Supply integrand as a table.");
        Console.WriteLine("  T = 10, and N increases");
        Console.WriteLine("");
        Console.WriteLine("       N    Approximate             Exact                   Error");
        Console.WriteLine("");

        const double a = 0.0;
        const double b = 2.0 * Math.PI;

        for (j = 1; j <= 6; j++)
        {
            int n = (int)Math.Pow(2, j) * 10 + 1;
            //
            //  Set the X values.
            //
            double[] x = new double[n];
            int      i;
            for (i = 0; i < n; i++)
            {
                x[i] = ((n - i - 1) * a
                        + i * b)
                       / (n - 1);
            }

            double[] ftab = log_integrand(n, x);

            double t = 10.0;

            double result = Filon.filon_tab_sin(n, ftab, a, b, t);

            double exact = -0.19762680771872;
            double error = result - exact;

            Console.WriteLine(n.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + result.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "  "
                              + exact.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "  "
                              + error.ToString(CultureInfo.InvariantCulture).PadLeft(24) + "");
        }
    }