Example #1
0
    private static void shepard_value_1d_test()

//****************************************************************************80
//
//  Purpose:
//
//    SHEPARD_VALUE_1D_TEST tests SHEPARD_VALUE_1D.
//
//  Discussion:
//
//    f(x) = x^3 - 12 x^2 + 39 x - 28 = ( x - 1 ) * ( x - 4 ) * ( x - 7 )
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license.
//
//  Modified:
//
//    03 July 2015
//
//  Author:
//
//    John Burkardt
//
    {
        const int nd = 4;
        const int ni = 21;

        double[] xd =
        {
            0.0, 2.0, 5.0, 10.0
        }

        ;
        double[] yd =
        {
            -28.0, +10.0, -8.0, +162.0
        }

        ;

        Console.WriteLine("");
        Console.WriteLine("SHEPARD_VALUE_1D_TEST:");
        Console.WriteLine("  SHEPARD_VALUE_1D evaluates a Shepard 1D interpolant.");

        const double p = 2.0;

        Console.WriteLine("");
        Console.WriteLine("  Using power P = " + p + "");

        const double x_min = 0.0;
        const double x_max = 10.0;

        double[] xi = typeMethods.r8vec_linspace_new(ni, x_min, x_max);

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

        typeMethods.r8vec2_print(ni, xi, yi, "  Table of interpolant values:");
    }
        public IActionResult Modify(int id, Shepard shepard)
        {
            Sheep sheep = Sheep.FindASheep(id);

            if (sheep != null)
            {
                sheep.Shepards.Add(shepard);
                //Sheep.UpdateASheep(sheep);
                return(PartialView("../Home/_ListShepard", sheep.Shepards));
            }
            return(RedirectResult("Index", "Home"));
        }
Example #3
0
    private static void shepard_basis_1d_test()
//****************************************************************************80
//
//  Purpose:
//
//    SHEPARD_BASIS_1D_TEST tests SHEPARD_BASIS_1D.
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license.
//
//  Modified:
//
//    02 July 2015
//
//  Author:
//
//    John Burkardt
//
    {
        const int    nd = 4;
        const int    ni = 21;
        const double p  = 2.0;

        double[] xd =
        {
            0.0, 2.0, 5.0, 10.0
        }

        ;

        Console.WriteLine("");
        Console.WriteLine("SHEPARD_BASIS_1D_TEST:");
        Console.WriteLine("  SHEPARD_BASIS_1D evaluates the Shepard 1D basis");
        Console.WriteLine("  functions.");
        Console.WriteLine("");
        Console.WriteLine("  Using power P = " + p + "");

        const double x_min = 0.0;
        const double x_max = 10.0;

        double[] xi = typeMethods.r8vec_linspace_new(ni, x_min, x_max);

        double[] lb = Shepard.shepard_basis_1d(nd, xd, p, ni, xi);

        typeMethods.r8mat_print(ni, nd, lb, "  The Shepard basis functions:");
    }
Example #4
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 + "");
    }
Example #5
0
    private static void test01(int prob, double p)
//****************************************************************************80
//
//  Purpose:
//
//    TEST01 tests SHEPARD_VALUE_1D.
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license.
//
//  Modified:
//
//    01 October 2012
//
//  Author:
//
//    John Burkardt
//
    {
        int i;

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

        int dim_num = TestInterp.p00_dim_num(prob);

        int nd = TestInterp.p00_data_num(prob);

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

        double[] xy = TestInterp.p00_data(prob, dim_num, nd);

        switch (p)
        {
        case 0.0:
            typeMethods.r8mat_transpose_print(2, nd, xy, "  Data array:");
            break;
        }

        double[] xd = new double[nd];
        double[] yd = new double[nd];

        for (i = 0; i < nd; i++)
        {
            xd[i] = xy[0 + i * 2];
            yd[i] = xy[1 + i * 2];
        }

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

        double[] xi = new double[ni];
        for (i = 0; i < ni; i++)
        {
            xi[i] = xd[i];
        }

        double[] yi = Shepard.shepard_value_1d(nd, xd, yd, p, 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 xmin = typeMethods.r8vec_min(nd, xd);
        double xmax = typeMethods.r8vec_max(nd, xd);
        double ymin = typeMethods.r8vec_min(nd, yd);
        double ymax = typeMethods.r8vec_max(nd, yd);

        ni = 501;
        xi = typeMethods.r8vec_linspace_new(ni, xmin, xmax);
        yi = Shepard.shepard_value_1d(nd, xd, yd, p, ni, xi);

        double ld = 0.0;

        for (i = 0; i < nd - 1; i++)
        {
            ld += Math.Sqrt(Math.Pow((xd[i + 1] - xd[i]) / (xmax - xmin), 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]) / (xmax - xmin), 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 Shepard interpolant          = " + li + "");
    }
 public IActionResult Update([Bind] Shepard shepard)
 {
     (Sheep sheep, Shepard shepard2) = Sheep.FindAShepard(shepard.Name);
     ViewBag.SheepId = sheep.Id;
     return(PartialView("Create", shepard2));
 }
Example #7
0
    private static void test01(int prob, double p, int m, int nd)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests SHEPARD_INTERP on an irregular grid.
    //
    //  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, double P, the power used in the distance weighting.
    //
    //    Input, int M, the spatial dimension.
    //
    //    Input, int ND, the number of data points.
    //
    {
        Console.WriteLine("");
        Console.WriteLine("TEST01:");
        Console.WriteLine("  Interpolate data from TEST_INTERP_ND problem #" + prob + "");
        Console.WriteLine("  using Shepard interpolation with P = " + p + "");
        Console.WriteLine("  spatial dimension M = " + m + "");
        Console.WriteLine("  and an irregular grid of ND = " + nd + " data points.");
        //
        //  Set problem parameters:
        //
        int seed = 123456789;

        double[] c = UniformRNG.r8vec_uniform_01_new(m, ref seed);
        double[] w = UniformRNG.r8vec_uniform_01_new(m, ref seed);

        double[] xd = UniformRNG.r8mat_uniform_01_new(m, nd, ref seed);

        double[] zd = Data_nD.p00_f(prob, m, c, w, nd, xd);
        //
        //  #1:  Does interpolant match function at interpolation points?
        //
        int ni = nd;

        double[] xi = typeMethods.r8mat_copy_new(m, ni, xd);
        double[] zi = Shepard.shepard_interp_nd(m, nd, xd, zd, p, ni, xi);

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

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

        //
        //  #2: Approximation test.  Estimate the integral (f-interp(f))^2.
        //
        ni = 1000;
        ni = 50;
        xi = UniformRNG.r8mat_uniform_01_new(m, ni, ref seed);
        zi = Shepard.shepard_interp_nd(m, nd, xd, zd, p, ni, xi);
        double[] ze = Data_nD.p00_f(prob, m, c, w, ni, xi);

        double app_error = typeMethods.r8vec_norm_affine(ni, zi, ze) / ni;

        Console.WriteLine("  L2 approximation error averaged per 1000 samples =     " + app_error + "");
    }
Example #8
0
    private static void test02(int prob, double p, int m, int n1d)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests SHEPARD_INTERP_ND on a regular N1D^M grid.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    03 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROB, the problem number.
    //
    //    Input, double P, the power used in the distance weighting.
    //
    //    Input, int M, the spatial dimension.
    //
    //    Input, int N1D, the number of points in 1D.
    //
    {
        int i;
        //
        //  Set problem parameters:
        //
        int seed = 123456789;

        double[] c = UniformRNG.r8vec_uniform_01_new(m, ref seed);
        double[] w = UniformRNG.r8vec_uniform_01_new(m, ref seed);

        int nd = (int)Math.Pow(n1d, m);

        Console.WriteLine("");
        Console.WriteLine("TEST02:");
        Console.WriteLine("  Interpolate data from TEST_INTERP_ND problem #" + prob + "");
        Console.WriteLine("  using Shepard interpolation with P = " + p + "");
        Console.WriteLine("  spatial dimension M = " + m + "");
        Console.WriteLine("  and a regular grid of N1D^M = " + nd + " data points.");

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

        double[] x1d = typeMethods.r8vec_linspace_new(n1d, a, b);

        double[] xd = new double[m * nd];
        for (i = 0; i < m; i++)
        {
            typeMethods.r8vecDPData data = new();
            typeMethods.r8vec_direct_product(ref data, i, n1d, x1d, m, nd, ref xd);
        }

        double[] zd = Data_nD.p00_f(prob, m, c, w, nd, xd);
        //
        //  #1:  Does interpolant match function at interpolation points?
        //
        int ni = nd;

        double[] xi = typeMethods.r8mat_copy_new(m, nd, xd);
        double[] zi = Shepard.shepard_interp_nd(m, nd, xd, zd, p, ni, xi);

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

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

        //
        //  #2: Approximation test.  Estimate the integral (f-interp(f))^2.
        //
        ni = 1000;
        xi = UniformRNG.r8mat_uniform_01_new(m, ni, ref seed);

        zi = Shepard.shepard_interp_nd(m, nd, xd, zd, p, ni, xi);

        double[] ze = Data_nD.p00_f(prob, m, c, w, ni, xi);

        double app_error = typeMethods.r8vec_norm_affine(ni, zi, ze) / ni;

        Console.WriteLine("  L2 approximation error averaged per 1000 samples =     " + app_error + "");
    }