Example #1
0
    private static void test01(int prob, int g, double p)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests SHEPARD_INTERP_2D.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROB, the problem number.
    //
    //    Input, int G, the grid number.
    //
    //    Input, double P, the power used in the distance weighting.
    //
    {
        const bool debug = false;

        Console.WriteLine("");
        Console.WriteLine("TEST01:");
        Console.WriteLine("  Interpolate data from TEST_INTERP_2D problem #" + prob + "");
        Console.WriteLine("  using grid #" + g + "");
        Console.WriteLine("  using Shepard interpolation with P = " + p + "");

        int nd = Data_2D.g00_size(g);

        Console.WriteLine("  Number of data points = " + nd + "");

        double[] xd = new double[nd];
        double[] yd = new double[nd];
        Data_2D.g00_xy(g, nd, ref xd, ref yd);

        double[] zd = new double[nd];
        Data_2D.f00_f0(prob, nd, xd, yd, ref zd);

        switch (debug)
        {
        case true:
            typeMethods.r8vec3_print(nd, xd, yd, zd, "  X, Y, Z data:");
            break;
        }

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

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

        double[] zi = Shepard.shepard_interp_2d(nd, xd, yd, zd, p, ni, xi, yi);

        double int_error = typeMethods.r8vec_norm_affine(ni, zi, zd) / ni;

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