Exemplo n.º 1
0
    private static void lageven_interp_1d_test(int prob, int nd)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LAGEVEN_INTERP_1D_TEST tests LAGEVEN_INTERP_1D.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    30 September 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROB, the problem index.
    //
    //    Input, int ND, the number of data points to use.
    //
    {
        Console.WriteLine("");
        Console.WriteLine("LAGEVEN_INTERP_1D_TEST:");
        Console.WriteLine("  LAGEVEN_INTERP_1D uses even spacing for data points.");
        Console.WriteLine("  Interpolate data from TEST_INTERP_1D problem #" + prob + "");
        Console.WriteLine("  Number of data points = " + nd + "");
        //
        //  Define the data.
        //
        const double a = 0.0;
        const double b = +1.0;

        double[] xd = typeMethods.r8vec_midspace_new(nd, a, b);
        double[] yd = Data_1D.p00_f(prob, nd, xd);

        switch (nd)
        {
        case < 10:
            typeMethods.r8vec2_print(nd, xd, yd, "  Data array:");
            break;
        }

        //
        //  #1:  Does the interpolant match the function at the interpolation points?
        //
        double[] xi = typeMethods.r8vec_copy_new(nd, xd);
        double[] yi = BarycentricInterp1D.lageven_interp_1d(nd, xd, yd, nd, xi);

        double int_error = typeMethods.r8vec_norm_affine(nd, yi, yd) / nd;

        Console.WriteLine("");
        Console.WriteLine("  L2 interpolation error averaged per interpolant node = " + int_error + "");
    }
Exemplo n.º 2
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for VANDERMONDE_APPROX_1D_TEST.
    //
    //  Discussion:
    //
    //    VANDERMONDE_APPROX_1D_TEST tests the VANDERMONDE_APPROX_1D library.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    10 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int[]     m_test     = { 0, 1, 2, 3, 4, 5, 9, 12 };
        const int m_test_num = 8;
        int       prob;

        Console.WriteLine("");
        Console.WriteLine("VANDERMONDE_APPROX_1D_TEST:");
        Console.WriteLine("  Test the VANDERMONDE_APPROX_1D library.");
        Console.WriteLine("  The R8LIB library is needed.");
        Console.WriteLine("  The QR_SOLVE library is needed.");
        Console.WriteLine("  The test needs the TEST_INTERP libary.");

        int prob_num = Data_1D.p00_prob_num();

        for (prob = 1; prob <= prob_num; prob++)
        {
            int j;
            for (j = 0; j < m_test_num; j++)
            {
                int m = m_test[j];
                test01(prob, m);
            }
        }

        Console.WriteLine("");
        Console.WriteLine("VANDERMONDE_APPROX_1D_TEST:");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }
Exemplo n.º 3
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for NEAREST_INTERP_1D_TEST.
    //
    //  Discussion:
    //
    //    NEAREST_INTERP_1D_TEST tests the NEAREST_INTERP_1D library.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    29 May 2013
    //
    //  Author:
    //
    //   John Burkardt
    //
    {
        int prob;

        Console.WriteLine("");
        Console.WriteLine("NEAREST_INTERP_1D_TEST:");
        Console.WriteLine("  Test the NEAREST_INTERP_1D library.");
        Console.WriteLine("  The test needs the TEST_INTERP library.");

        int prob_num = Data_1D.p00_prob_num();

        int ni = 11;

        for (prob = 1; prob <= prob_num; prob++)
        {
            nearest_interp_1d_test01(prob, ni);
        }

        for (prob = 1; prob <= prob_num; prob++)
        {
            nearest_interp_1d_test02(prob);
        }

        Console.WriteLine("");
        Console.WriteLine("NEAREST_INTERP_1D_TEST:");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }
Exemplo n.º 4
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NEWTON_INTERP_1D_TEST tests the NEWTON_INTERP_1D library.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    10 July 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int prob;

        Console.WriteLine("");
        Console.WriteLine("NEWTON_INTERP_1D_TEST:");
        Console.WriteLine("  Test the NEWTON_INTERP_1D library.");
        Console.WriteLine("  The R8LIB library is needed.");
        Console.WriteLine("  This test needs the TEST_INTERP library as well.");

        newton_coef_1d_test();

        newton_value_1d_test();

        int prob_num = Data_1D.p00_prob_num();

        for (prob = 1; prob <= prob_num; prob++)
        {
            newton_interp_1d_test01(prob);
        }

        Console.WriteLine("");
        Console.WriteLine("NEWTON_INTERP_1D_TEST:");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }
Exemplo n.º 5
0
    private static void test01(int prob, int nc, int nd)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests PWL_APPROX_1D.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    10 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROB, the problem index.
    //
    //    Input, int NC, the number of control points.
    //
    //    Input, int ND, the number of data points.
    //
    {
        Console.WriteLine("");
        Console.WriteLine("TEST01:");
        Console.WriteLine("  Approximate data from TEST_INTERP_1D problem #" + prob + "");
        Console.WriteLine("  Number of control points = " + nc + "");
        Console.WriteLine("  Number of data points = " + nd + "");

        const double xmin = 0.0;
        const double xmax = 1.0;

        double[] xd = typeMethods.r8vec_linspace_new(nd, xmin, xmax);
        double[] yd = Data_1D.p00_f(prob, nd, xd);

        switch (nd)
        {
        case < 10:
            typeMethods.r8vec2_print(nd, xd, yd, "  Data array:");
            break;
        }

        //
        //  Determine control values.
        //
        double[] xc = typeMethods.r8vec_linspace_new(nc, xmin, xmax);
        double[] yc = Approx1D.pwl_approx_1d(nd, xd, yd, nc, xc);
        //
        //  #1:  Does approximant come close to function at data points?
        //
        double[] xi = typeMethods.r8vec_copy_new(nd, xd);
        double[] yi = Approx1D.pwl_interp_1d(nc, xc, yc, nd, xi);

        double app_error = typeMethods.r8vec_norm_affine(nd, yi, yd) / nd;

        Console.WriteLine("");
        Console.WriteLine("  L2 approximation error averaged per data node = " + app_error + "");
    }
Exemplo n.º 6
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for BARYCENTRIC_INTERP_1D_TEST.
    //
    //  Discussion:
    //
    //    BARYCENTRIC_INTERP_1D_TEST tests the BARYCENTRIC_INTERP_1D library.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    30 September 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int i;
        int nd;

        int[] nd_test =
        {
            4, 8, 16, 32, 64, 1000
        }

        ;
        const int nd_test_num = 6;
        int       prob;

        Console.WriteLine("");
        Console.WriteLine("BARYCENTRIC_INTERP_1D_TEST:");
        Console.WriteLine("  Test the BARYCENTRIC_INTERP_1D library.");
        Console.WriteLine("  The R8LIB library is needed.");
        Console.WriteLine("  The tests need the TEST_INTERP_1D library.");

        int prob_num = Data_1D.p00_prob_num();

        for (prob = 1; prob <= prob_num; prob++)
        {
            for (i = 0; i < nd_test_num; i++)
            {
                nd = nd_test[i];
                lagcheby1_interp_1d_test(prob, nd);
            }
        }

        for (prob = 1; prob <= prob_num; prob++)
        {
            for (i = 0; i < nd_test_num; i++)
            {
                nd = nd_test[i];
                lagcheby2_interp_1d_test(prob, nd);
            }
        }

        for (prob = 1; prob <= prob_num; prob++)
        {
            for (i = 0; i < nd_test_num; i++)
            {
                nd = nd_test[i];
                lageven_interp_1d_test(prob, nd);
            }
        }

        Console.WriteLine("");
        Console.WriteLine("BARYCENTRIC_INTERP_1D_TEST:");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }
Exemplo n.º 7
0
    private static void test02(int prob, int m, int nd)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests LAGRANGE_APPROX_1D with evenly spaced data
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    09 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROB, the problem index.
    //
    //    Input, int M, the polynomial approximant degree.
    //
    //    Input, int ND, the number of data points.
    //
    {
        Console.WriteLine("");
        Console.WriteLine("TEST02:");
        Console.WriteLine("  Approximate evenly spaced data from TEST_INTERP_1D problem #" + prob + "");
        Console.WriteLine("  Use polynomial approximant of degree " + m + "");
        Console.WriteLine("  Number of data points = " + nd + "");

        const double a = 0.0;
        const double b = 1.0;

        double[] xd = typeMethods.r8vec_linspace_new(nd, a, b);

        double[] yd = Data_1D.p00_f(prob, nd, xd);

        switch (nd)
        {
        case < 10:
            typeMethods.r8vec2_print(nd, xd, yd, "  Data array:");
            break;
        }

        //
        //  #1:  Does approximant come close to function at data points?
        //
        int ni = nd;

        double[] xi = typeMethods.r8vec_copy_new(ni, xd);
        double[] yi = Lagrange1D.lagrange_approx_1d(m, nd, xd, yd, ni, xi);

        double int_error = typeMethods.r8vec_norm_affine(nd, yi, yd) / ni;

        Console.WriteLine("");
        Console.WriteLine("  L2 approximation error averaged per data node = " + int_error + "");
    }
Exemplo n.º 8
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for LAGRANGE_APPROX_1D_TEST.
    //
    //  Discussion:
    //
    //    LAGRANGE_APPROX_1D_TEST tests the LAGRANGE_APPROX_1D library.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    09 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int j;
        int k;
        int m;

        int[] m_test =
        {
            0, 1, 2, 3, 4, 8, 16
        }

        ;
        const int m_test_num = 7;
        int       nd;

        int[] nd_test =
        {
            16, 64, 1000
        }

        ;
        const int nd_test_num = 3;
        int       prob;

        Console.WriteLine("");
        Console.WriteLine("LAGRANGE_APPROX_1D_TEST:");
        Console.WriteLine("  Test the LAGRANGE_APPROX_1D library.");
        Console.WriteLine("  The R8LIB library is needed.");
        Console.WriteLine("  The QR_SOLVE library is needed.");
        Console.WriteLine("  These tests need the TEST_INTERP_1D library.");

        int prob_num = Data_1D.p00_prob_num();

        for (prob = 1; prob <= prob_num; prob++)
        {
            for (j = 0; j < m_test_num; j++)
            {
                m = m_test[j];
                for (k = 0; k < nd_test_num; k++)
                {
                    nd = nd_test[k];
                    test02(prob, m, nd);
                }
            }
        }

        for (prob = 1; prob <= prob_num; prob++)
        {
            for (j = 0; j < m_test_num; j++)
            {
                m = m_test[j];
                for (k = 0; k < nd_test_num; k++)
                {
                    nd = nd_test[k];
                    test03(prob, m, nd);
                }
            }
        }

        //
        //  Terminate.
        //
        Console.WriteLine("");
        Console.WriteLine("LAGRANGE_APPROX_1D_TEST:");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }
Exemplo n.º 9
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for LAGRANGE_INTERP_1D_TEST.
    //
    //  Discussion:
    //
    //    LAGRANGE_INTERP_1D_TEST tests the LAGRANGE_INTERP_1D library.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    14 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int nd_test_num = 6;

        int j;
        int nd;

        int[] nd_test =
        {
            4, 8, 16, 32, 64, 256
        }

        ;
        int prob;

        Console.WriteLine("");
        Console.WriteLine("LAGRANGE_INTERP_1D_TEST:");
        Console.WriteLine("  Test the LAGRANGE_INTERP_1D library.");
        Console.WriteLine("  The R8LIB library is needed.");
        Console.WriteLine("  These tests need the TEST_INTERP_1D library.");

        int prob_num = Data_1D.p00_prob_num();

        for (prob = 1; prob <= prob_num; prob++)
        {
            for (j = 0; j < nd_test_num; j++)
            {
                nd = nd_test[j];
                test01(prob, nd);
            }
        }

        for (prob = 1; prob <= prob_num; prob++)
        {
            for (j = 0; j < nd_test_num; j++)
            {
                nd = nd_test[j];
                test02(prob, nd);
            }
        }

        //
        //  Terminate.
        //
        Console.WriteLine("");
        Console.WriteLine("LAGRANGE_INTERP_1D_TEST:");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }
Exemplo n.º 10
0
    private static void test01(int prob, int nd)

    //*****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests LAGRANGE_VALUE_1D with evenly spaced data.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    12 September 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROB, the problem index.
    //
    //    Input, int ND, the number of data points to use.
    //
    {
        int i;

        Console.WriteLine("");
        Console.WriteLine("TEST01:");
        Console.WriteLine("  Interpolate data from TEST_INTERP_1D problem #" + prob + "");
        Console.WriteLine("  Use even spacing for data points.");
        Console.WriteLine("  Number of data points = " + nd + "");

        const double a = 0.0;
        const double b = 1.0;

        double[] xd = typeMethods.r8vec_linspace_new(nd, a, b);

        double[] yd = Data_1D.p00_f(prob, nd, xd);

        switch (nd)
        {
        case < 10:
            typeMethods.r8vec2_print(nd, xd, yd, "  Data array:");
            break;
        }

        //
        //  #1:  Does interpolant match function at interpolation points?
        //
        int ni = nd;

        double[] xi = typeMethods.r8vec_copy_new(ni, xd);
        double[] yi = Lagrange1D.lagrange_value_1d(nd, xd, yd, ni, xi);

        double int_error = typeMethods.r8vec_norm_affine(nd, yi, yd) / ni;

        Console.WriteLine("");
        Console.WriteLine("  L2 interpolation error averaged per interpolant node = " + int_error + "");

        //
        //  #2: Compare estimated curve length to piecewise linear (minimal) curve length.
        //  Assume data is sorted, and normalize X and Y dimensions by (XMAX-XMIN) and
        //  (YMAX-YMIN).
        //
        double ymin = typeMethods.r8vec_min(nd, yd);
        double ymax = typeMethods.r8vec_max(nd, yd);

        ni = 501;
        xi = typeMethods.r8vec_linspace_new(ni, a, b);
        yi = Lagrange1D.lagrange_value_1d(nd, xd, yd, ni, xi);

        double ld = 0.0;

        for (i = 0; i < nd - 1; i++)
        {
            ld += Math.Sqrt(Math.Pow((xd[i + 1] - xd[i]) / (b - a), 2)
                            + Math.Pow((yd[i + 1] - yd[i]) / (ymax - ymin), 2));
        }

        double li = 0.0;

        for (i = 0; i < ni - 1; i++)
        {
            li += Math.Sqrt(Math.Pow((xi[i + 1] - xi[i]) / (b - a), 2)
                            + Math.Pow((yi[i + 1] - yi[i]) / (ymax - ymin), 2));
        }

        Console.WriteLine("");
        Console.WriteLine("  Normalized length of piecewise linear interpolant = " + ld + "");
        Console.WriteLine("  Normalized length of polynomial interpolant       = " + li + "");
    }