示例#1
0
        private void button9_Click(object sender, EventArgs e)
        {
            try
            {
                string fn           = @"C:\Users\Миша\OneDrive\графики\Fisher\Fisher_alpha_001.xml";
                var    tmpInterp001 = Interp2D.LoadFromXmlFile(fn);
                fn = @"C:\Users\Миша\OneDrive\графики\Fisher\Fisher_alpha_01.xml";
                var tmpInterp01 = Interp2D.LoadFromXmlFile(fn);
                fn = @"C:\Users\Миша\OneDrive\графики\Fisher\Fisher_alpha_005.xml";
                var tmpInterp005 = Interp2D.LoadFromXmlFile(fn);
                fn = @"C:\Users\Миша\OneDrive\графики\Fisher\Fisher_alpha_0025.xml";
                var tmpInterp0025 = Interp2D.LoadFromXmlFile(fn);

                var tmpInterp = new Interp3D();
                tmpInterp.AddElement(0.1, tmpInterp01);
                tmpInterp.AddElement(0.05, tmpInterp005);
                tmpInterp.AddElement(0.025, tmpInterp0025);
                tmpInterp.AddElement(0.01, tmpInterp001);



                tmpInterp.SaveToXmlFile(@"C:\Users\Миша\OneDrive\графики\Fisher\Fisher_3D.xml");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        protected void LoadMe()
        {
            var resourses = Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true);

            foreach (DictionaryEntry item in resourses)
            {
                string key = item.Key.ToString();
                if (key.EndsWith("4D"))
                {
                    _graphs.Add(CutMyString(key),
                                Interp4D.LoadFromXmlString(item.Value.ToString()));
                }
                else if (key.EndsWith("3D"))
                {
                    _graphs.Add(CutMyString(key),
                                Interp3D.LoadFromXmlString(item.Value.ToString()));
                }
                else if (key.EndsWith("1D"))
                {
                    _graphs.Add(CutMyString(key),
                                InterpXY.LoadFromXmlString(item.Value.ToString()));
                }
                else if (key.EndsWith("4P"))
                {
                    _graphs.Add(CutMyString(key),
                                PotentGraff4P.LoadFromXmlString(item.Value.ToString()));
                }
                else
                {
                    _graphs.Add(CutMyString(key),
                                Interp2D.LoadFromXmlString(item.Value.ToString()));
                }
            }
        }
示例#3
0
 private void button4_Click(object sender, EventArgs e)
 {
     if (checkedListBox1.SelectedIndex < 0)
     {
         return;
     }
     if (checkedListBox1.SelectedIndices.Count == 0)
     {
         MessageBox.Show("Не выделено ни одного интерполятора(");
         return;
     }
     if (_sd.ShowDialog() == DialogResult.OK)
     {
         var tmpInterp2D = new Interp2D();
         if (radioButton6.Checked)
         {
             tmpInterp2D.ET_left = ExtrapolType.etZero;
         }
         if (radioButton5.Checked)
         {
             tmpInterp2D.ET_left = ExtrapolType.etValue;
         }
         if (radioButton4.Checked)
         {
             tmpInterp2D.InterpType = InterpolType.itStep;
         }
         if (radioButton3.Checked)
         {
             tmpInterp2D.InterpType = InterpolType.itLine;
         }
         if (radioButton2.Checked)
         {
             tmpInterp2D.ET_right = ExtrapolType.etZero;
         }
         if (radioButton1.Checked)
         {
             tmpInterp2D.ET_right = ExtrapolType.etValue;
         }
         foreach (var item in checkedListBox1.CheckedItems)
         {
             tmpInterp2D.AddElement(Convert.ToDouble((item as InterpXY).Title),
                                    (item as InterpXY));
         }
         tmpInterp2D.SaveToXmlFile(_sd.FileName);
         //XmlSerializer serial = new XmlSerializer(typeof(Interp2D));
         //var sw = new StreamWriter(sd.FileName);
         //serial.Serialize(sw, tmpInterp2D);
         //sw.Close();
     }
 }
示例#4
0
        public void ImportDataFromMatrixTest()
        {
            var interp2D = new Interp2D();

            interp2D.ImportDataFromMatrix(new double[4, 5]
            {
                { 0, 0, 20, 30, 40 },
                { 0, -1, -2, -3, -3 },
                { 2, 1, 2, 3, 1 },
                { -1, 0, 3, 0, -1 }
            });
            Assert.AreEqual(1.5, interp2D.GetV(-1, 10), 0.00001);
            Assert.AreEqual(0, interp2D.GetV(1, 21), 0.00001);
            Assert.AreEqual(2, interp2D.GetV(2, 35), 0.0001);
        }
示例#5
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (_od.ShowDialog() == DialogResult.OK)
     {
         try
         {
             var tmpInterp2D = Interp2D.LoadFromXmlFile(_od.FileName);
             foreach (var item in tmpInterp2D.Data)
             {
                 item.Value.Title = item.Key.ToString();
                 AddInterp(item.Value);
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
示例#6
0
 private void button7_Click(object sender, EventArgs e)
 {
     try
     {
         var od = new OpenFileDialog()
         {
             Filter      = "CSV Files|*.csv",
             Multiselect = true
         };
         if (od.ShowDialog() == DialogResult.OK)
         {
             foreach (var fileName in od.FileNames)
             {
                 var lines = File.ReadAllLines(fileName).Select(a => a.Split(';'));
                 var matr  = new double[lines.Count(), lines.First().Count()];
                 int i     = 0;
                 foreach (var items in lines)
                 {
                     int j = 0;
                     foreach (var item in items)
                     {
                         //MessageBox.Show($"i={i}, j={j++}, val={Convert.ToDouble(item.Replace('.',',').Trim())}");
                         matr[i, j++] = Convert.ToDouble(item.Replace('.', ',').Trim());
                     }
                     i++;
                 }
                 var interp2D = new Interp2D();
                 interp2D.ImportDataFromMatrix(matr);
                 foreach (var item in interp2D.Data)
                 {
                     item.Value.Title = item.Key.ToString();
                 }
                 interp2D.SaveToXmlFile(Path.ChangeExtension(fileName, ".xml"));
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#7
0
        private void button8_Click(object sender, EventArgs e)
        {
            var interp3 = new Interp3D();

            var dir = @"C:\Users\Миша\OneDrive\графики\5_16";

            interp3.Title = "5_16";
            Dictionary <double, string> makeFile = new Dictionary <double, string>()
            {
                [100.0] = dir + "\\" + interp3.Title + ".xml"
            };

            foreach (var item in makeFile)
            {
                interp3.AddElement(item.Key, Interp2D.LoadFromXmlFile(item.Value));
            }
            var et1 = new Interp2D();

            et1.AddElement(0.0, new InterpXY(new double[] { 0.0 }, new double[] { 0.0 }));
            interp3.AddElement(1.0, et1);
            string str = dir + "\\" + interp3.Title + "_3D.xml";

            interp3.SaveToXmlFile(str);
        }
示例#8
0
    private static void test01(int prob, int n)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    PWL_INTERP_2D_TEST01 tests PWL_INTERP_2D.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    15 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROB, the problem number.
    //
    //    Input, int N, the grid size in each dimension.
    //
    {
        int i;
        int j;

        Console.WriteLine("");
        Console.WriteLine("PWL_INTERP_2D_TEST01:");
        Console.WriteLine("  Interpolate data from TEST_INTERP_2D problem # " + prob + "");
        Console.WriteLine("  Using polynomial interpolant of product degree " + n + " x " + n + "");

        int nd = n * n;

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

        double[] xd_1d = typeMethods.r8vec_linspace_new(n, 0.0, 1.0);
        double[] yd_1d = typeMethods.r8vec_linspace_new(n, 0.0, 1.0);

        double[] xd = new double[n * n];
        double[] yd = new double[n * n];
        double[] zd = new double[n * n];

        int ij = 0;

        for (j = 0; j < n; j++)
        {
            for (i = 0; i < n; i++)
            {
                xd[ij] = xd_1d[i];
                yd[ij] = yd_1d[j];
                ij    += 1;
            }
        }

        Data_2D.f00_f0(prob, nd, xd, yd, ref zd);

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

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

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

        double[] zi = Interp2D.pwl_interp_2d(n, n, xd_1d, yd_1d, zd, ni, xi, yi);

        switch (ni)
        {
        case <= 20:
            typeMethods.r8vec3_print(ni, xi, yi, zi, "  X, Y, Z interpolation:");
            break;
        }

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

        Console.WriteLine("");
        Console.WriteLine("  RMS data interpolation error = " + int_error + "");

        switch (nd)
        {
        //
        //  #2:  Does interpolant approximate data at midpoints?
        //
        case > 1:
        {
            double[] xi_1d = new double[n - 1];
            double[] yi_1d = new double[n - 1];

            for (i = 0; i < n - 1; i++)
            {
                xi_1d[i] = 0.5 * (xd_1d[i] + xd_1d[i + 1]);
            }

            for (i = 0; i < n - 1; i++)
            {
                yi_1d[i] = 0.5 * (yd_1d[i] + yd_1d[i + 1]);
            }

            ni = (n - 1) * (n - 1);

            xi = new double[ni];
            yi = new double[ni];
            double[] zdm = new double[ni];

            ij = 0;
            for (j = 0; j < n - 1; j++)
            {
                for (i = 0; i < n - 1; i++)
                {
                    xi[ij] = xi_1d[i];
                    yi[ij] = yi_1d[j];
                    ij    += 1;
                }
            }

            Data_2D.f00_f0(prob, ni, xi, yi, ref zdm);

            zi = Interp2D.pwl_interp_2d(n, n, xd_1d, yd_1d, zd, ni, xi, yi);

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

            Console.WriteLine("  RMS data approximation error = " + app_error + "");
            break;
        }
        }
    }
示例#9
0
    private static void test03(int prob)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST03 tests PWL_INTERP_2D_SCATTERED_VALUE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    25 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       element_num = 0;
        int       i;
        int       j;
        const int ni = 25;

        double[] xi  = new double[25];
        double[] xyi = new double[2 * 25];
        double[] yi  = new double[25];

        const int g  = 2;
        int       nd = Data_2D.g00_size(g);

        Console.WriteLine("");
        Console.WriteLine("TEST03");
        Console.WriteLine("  PWL_INTERP_2D_SCATTERED_VALUE evaluates a");
        Console.WriteLine("  piecewise linear interpolant to scattered data.");
        Console.WriteLine("  Here, we use grid number " + g + "");
        Console.WriteLine("  with " + nd + " scattered points in the unit square");
        Console.WriteLine("  on problem " + prob + "");
        //
        //  Get the data points and evaluate the function there.
        //
        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);

        double[] xyd = new double[2 * nd];

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

        //
        //  Set up the Delaunay triangulation.
        //
        int[] element_neighbor = new int[3 * 2 * nd];
        int[] triangle         = new int[3 * 2 * nd];

        Delauney.r8tris2(nd, ref xyd, ref element_num, ref triangle, ref element_neighbor);

        for (j = 0; j < element_num; j++)
        {
            for (i = 0; i < 3; i++)
            {
                switch (element_neighbor[i + j * 3])
                {
                case > 0:
                    element_neighbor[i + j * 3] -= 1;
                    break;
                }
            }
        }

        //
        //  Define the interpolation points.
        //
        int k = 0;

        for (i = 1; i <= 5; i++)
        {
            for (j = 1; j <= 5; j++)
            {
                xyi[0 + k * 2] = (2 * i - 1) / 10.0;
                xyi[1 + k * 2] = (2 * j - 1) / 10.0;
                k += 1;
            }
        }

        for (k = 0; k < ni; k++)
        {
            xi[k] = xyi[0 + k * 2];
            yi[k] = xyi[1 + k * 2];
        }

        double[] ze = new double[ni];
        Data_2D.f00_f0(prob, ni, xi, yi, ref ze);
        //
        //  Evaluate the interpolant.
        //
        double[] zi = Interp2D.pwl_interp_2d_scattered_value(nd, xyd, zd, element_num,
                                                             triangle, element_neighbor, ni, xyi);

        double rms = 0.0;

        for (k = 0; k < ni; k++)
        {
            rms += Math.Pow(zi[k] - ze[k], 2);
        }

        rms = Math.Sqrt(rms / ni);

        Console.WriteLine("");
        Console.WriteLine("  RMS error is " + rms + "");

        Console.WriteLine("");
        Console.WriteLine("     K      Xi(K)       Yi(K)       Zi(K)       Z(X,Y)");
        Console.WriteLine("");

        for (k = 0; k < ni; k++)
        {
            Console.WriteLine("  " + k.ToString().PadLeft(4)
                              + "  " + xyi[0 + k * 2].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + xyi[1 + k * 2].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + zi[k].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + ze[k].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }
示例#10
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests PWL_INTERP_2D_SCATTERED_VALUE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    25 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int[]     element_neighbor = new int[3 * 2 * 9];
        int       element_num      = 0;
        int       i;
        int       j;
        const int ni       = 25;
        const int node_num = 9;

        double[] node_xy =
        {
            0.0, 0.0,
            0.0, 1.0,
            0.2, 0.5,
            0.3, 0.6,
            0.4, 0.5,
            0.6, 0.4,
            0.6, 0.5,
            1.0, 0.0,
            1.0, 1.0
        };
        int[]    triangle = new int[3 * 2 * 9];
        double[] xyi      = new double[2 * 25];
        double[] zd       = new double[9];

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  PWL_INTERP_2D_SCATTERED_VALUE evaluates a");
        Console.WriteLine("  piecewise linear interpolant to scattered data.");
        //
        //  Set up the Delaunay triangulation.
        //
        Delauney.r8tris2(node_num, ref node_xy, ref element_num, ref triangle, ref element_neighbor);

        for (j = 0; j < element_num; j++)
        {
            for (i = 0; i < 3; i++)
            {
                switch (element_neighbor[i + j * 3])
                {
                case > 0:
                    element_neighbor[i + j * 3] -= 1;
                    break;
                }
            }
        }

        Print.triangulation_order3_print(node_num, element_num, node_xy,
                                         triangle, element_neighbor);
        //
        //  Define the Z data.
        //
        for (i = 0; i < node_num; i++)
        {
            double x = node_xy[0 + i * 2];
            double y = node_xy[1 + i * 2];
            zd[i] = x + 2.0 * y;
        }

        //
        //  Define the interpolation points.
        //
        int k = 0;

        for (i = 0; i <= 4; i++)
        {
            for (j = 0; j <= 4; j++)
            {
                xyi[0 + k * 2] = (i - 1) / 4.0;
                xyi[1 + k * 2] = (j - 1) / 4.0;
                k += 1;
            }
        }

        //
        //  Evaluate the interpolant.
        //
        double[] zi = Interp2D.pwl_interp_2d_scattered_value(node_num, node_xy, zd, element_num,
                                                             triangle, element_neighbor, ni, xyi);

        Console.WriteLine("");
        Console.WriteLine("     K      Xi(K)       Yi(K)       Zi(K)       Z(X,Y)");
        Console.WriteLine("");
        for (k = 0; k < ni; k++)
        {
            double ze = xyi[0 + k * 2] + 2.0 * xyi[1 + k * 2];
            Console.WriteLine("  " + k.ToString().PadLeft(4)
                              + "  " + xyi[0 + k * 2].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + xyi[1 + k * 2].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + zi[k].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + ze.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }