Accord.Tests.Math.MatrixTest.MeshGridTest1 C# (CSharp) Method

MeshGridTest1() private method

private MeshGridTest1 ( ) : void
return void
        public void MeshGridTest1()
        {
            // The MeshGrid method generates two matrices that can be
            // used to generate all possible (x,y) pairs between two
            // vector of points. For example, let's suppose we have
            // the values:
            //
            double[] a = { 1, 2, 3 };
            double[] b = { 4, 5, 6 };

            // We can create a grid
            var grid = a.MeshGrid(b);

            // get the x-axis values
            double[,] x = grid.Item1;

            // get the y-axis values
            double[,] y = grid.Item2;


            // we can either use those matrices separately (such as for plotting 
            // purposes) or we can also generate a grid of all the (x,y) pairs as
            //
            double[,][] xy = x.ApplyWithIndex((v, i, j) => new[] { x[i, j], y[i, j] });

            double[,] ex =
            {
                { 1, 1, 1 },
                { 2, 2, 2 },
                { 3, 3, 3 },
            };

            double[,] ey =
            {
                { 4, 5, 6 },
                { 4, 5, 6 },
                { 4, 5, 6 },
            };

            double[, ,] expected =
            {
                { { 1, 4 }, { 1, 5 }, { 1, 6 } },
                { { 2, 4 }, { 2, 5 }, { 2, 6 } },
                { { 3, 4 }, { 3, 5 }, { 3, 6 } },
            };

            Assert.IsTrue(ex.IsEqual(x));
            Assert.IsTrue(ey.IsEqual(y));

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Assert.AreEqual(expected[i, j, 0], xy[i, j][0]);
                    Assert.AreEqual(expected[i, j, 1], xy[i, j][1]);
                }
            }
        }
MatrixTest