当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.Add方法代码示例

本文整理汇总了C#中System.Matrix.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Add方法的具体用法?C# Matrix.Add怎么用?C# Matrix.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Matrix的用法示例。


在下文中一共展示了Matrix.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExceptionIncompatibleMatrices

        public void ExceptionIncompatibleMatrices()
        {
            IMathematicalMatrix matrix1 = new Matrix(2, 3);
            matrix1[0, 0] = 1;
            matrix1[0, 1] = 2;
            matrix1[0, 2] = -4;
            matrix1[1, 0] = 0;
            matrix1[1, 1] = 3;
            matrix1[1, 2] = -1;

            IMathematicalMatrix matrix2 = MatrixTest.GetTestMatrix();

            matrix1.Add(matrix2);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:14,代码来源:Plus.cs

示例2: AddMatricesDiffSizeTest1

        public void AddMatricesDiffSizeTest1()
        {
            var matrix1 = new Matrix(new[]
            {
                new Vector(new[] { new Number(6), new Number(3) }),
                new Vector(new[] { new Number(2), new Number(1) })
            });
            var matrix2 = new Matrix(new[]
            {
                new Vector(new[] { new Number(9), new Number(2) }),
                new Vector(new[] { new Number(4), new Number(3), new Number(9) })
            });

            var result = matrix1.Add(matrix2);
        }
开发者ID:ronnycsharp,项目名称:xFunc,代码行数:15,代码来源:MatrixTest.cs

示例3: AddRaiseExceptionIfDifferentRowSize

        public void AddRaiseExceptionIfDifferentRowSize()
        {
            Matrix matrix1 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 } });
            Matrix matrix2 = new Matrix(new double[][] { new double[] { 5.0, 6.0 }, new double[] { 7.0, 8.0 }, new double[] { 9.0, 10.0 } });

            try
            {
                matrix1.Add(matrix2);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                Assert.AreEqual("Matrices have different sizes", ex.Message);
            }
        }
开发者ID:ajlopez,项目名称:MathelSharp,代码行数:16,代码来源:MatrixTests.cs

示例4: Add

        public void Add()
        {
            Matrix matrix1 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 } });
            Matrix matrix2 = new Matrix(new double[][] { new double[] { 5.0, 6.0 }, new double[] { 7.0, 8.0 } });

            Matrix matrix = matrix1.Add(matrix2);

            Assert.AreEqual(4, matrix.Size);

            var elements = matrix.Elements;

            Assert.AreEqual(1.0 + 5.0, elements[0][0]);
            Assert.AreEqual(2.0 + 6.0, elements[0][1]);
            Assert.AreEqual(3.0 + 7.0, elements[1][0]);
            Assert.AreEqual(4.0 + 8.0, elements[1][1]);
        }
开发者ID:ajlopez,项目名称:MathelSharp,代码行数:16,代码来源:MatrixTests.cs

示例5: AddMatricesDiffSizeTest2

        public void AddMatricesDiffSizeTest2()
        {
            var matrix1 = new Matrix(new[]
            {
                new Vector(new[] { new Number(6), new Number(3) }),
                new Vector(new[] { new Number(2), new Number(1) })
            });
            var matrix2 = new Matrix(new[]
            {
                new Vector(new[] { new Number(9), new Number(2) }),
                new Vector(new[] { new Number(4), new Number(3) }),
                new Vector(new[] { new Number(1), new Number(7) })
            });

            Assert.Throws<ArgumentException>(() => matrix1.Add(matrix2));
        }
开发者ID:sys27,项目名称:xFunc,代码行数:16,代码来源:MatrixTest.cs

示例6: Init

        public void Init()
        {
            matrix = new Matrix<double>();
            p = new Point<double>(10d, 10d);
            pos = new Position<double>();

            var n = new Random();

            for (int i = 0; i < MAX_POSITIONS; i++)
            {
                for (int j = 0; j < MAX_POINTS; j++)
                {
                    pos.Add(new Point<double>(n.NextDouble(), n.NextDouble()));
                }
                matrix.Add(pos);
            }
        }
开发者ID:Infatum,项目名称:PMC-Data-Model,代码行数:17,代码来源:MatrixTests.cs

示例7: OptionsForm

 public OptionsForm()
 {
     InitializeComponent();
     try
     {
         using (var reader = File.OpenText("math.default"))
         {
             var n = 0;
             var m = new Matrix<decimal>();
             var a = new Matrix<decimal>();
             var b = new Matrix<decimal>();
             var f = new Matrix<decimal>();
             var w = new Matrix<decimal>();
             for (var line = reader.ReadLine(); !string.IsNullOrWhiteSpace(line); line = reader.ReadLine())
             {
                 var arr = line.Split(' ');
                 if (arr[0][0] == 'N')
                 {
                     n = Convert.ToInt32(arr[1]);
                 }
                 else
                 {
                     var x = new Vector<decimal>();
                     for (var i = 1; i < arr.Length; i++) x.Add(Convert.ToDecimal(arr[i]));
                     if (arr[0][0] == 'M') m.Add(x);
                     if (arr[0][0] == 'A') a = new Matrix<decimal> {x};
                     if (arr[0][0] == 'B') b = new Matrix<decimal> {x};
                     if (arr[0][0] == 'F') f.Add(x);
                     if (arr[0][0] == 'W') w.Add(x);
                 }
             }
             numericUpDown1.Value = n;
             _matrixControlM.Value = m;
             _matrixControlA.Value = a;
             _matrixControlB.Value = b;
             _matrixControlF.Value = f;
             _matrixControlW.Value = w;
         }
     }
     catch (Exception ex)
     {
     }
 }
开发者ID:dprotopopov,项目名称:nonlinear,代码行数:43,代码来源:OptionsForm.cs

示例8: AddMatricesTest

        public void AddMatricesTest()
        {
            var matrix1 = new Matrix(new[]
            {
                new Vector(new[] { new Number(6), new Number(3) }),
                new Vector(new[] { new Number(2), new Number(1) })
            });
            var matrix2 = new Matrix(new[]
            {
                new Vector(new[] { new Number(9), new Number(2) }),
                new Vector(new[] { new Number(4), new Number(3) })
            });

            var expected = new Matrix(new[]
            {
                new Vector(new[] { new Number(15), new Number(5) }),
                new Vector(new[] { new Number(6), new Number(4) })
            });
            var result = matrix1.Add(matrix2);

            Assert.AreEqual(expected, result);
        }
开发者ID:ronnycsharp,项目名称:xFunc,代码行数:22,代码来源:MatrixTest.cs

示例9: Solve

        public long Solve()
        {
            var text = File.ReadAllLines(@"..\..\Problems\Problem082.txt");

            var matrix = new Matrix();

            var lineNumber = 0;
            var columnNumber = 0;
            foreach (var line in text)
            {
                foreach (var number in line.Split(','))
                {
                    matrix.Add(lineNumber, columnNumber, int.Parse(number));
                    columnNumber++;
                }
                lineNumber++;
                columnNumber = 0;
            }

            matrix.MinPath(0, 0);

            return matrix.GetMinPath(M - 1, M - 1);
        }
开发者ID:joeazbest,项目名称:Euler,代码行数:23,代码来源:Problem083.cs

示例10: Main

        static void Main(string[] args)
        {
            Point3D point1 = new Point3D(2,3,4);
            Point3D point2 = new Point3D(1,1,1);
            Console.WriteLine(CalculateDistance.calct(point1, point2));
            Path collection = new Path();
            collection.AddPoint(point1, point2);

            PathStorage.Save(collection.PathList, "Colection1");
            PathStorage.Save(collection.PathList, "Colection2");
            Console.WriteLine("Load \"Colection1\"");
            for (int i = 0; i < PathStorage.Load("Colection1").Count; i++)
            {
                Console.WriteLine("Point {0} cordinates: X={1}, Y={2}, Z={3}", i, PathStorage.Load("Colection1")[i].X, PathStorage.Load("Colection1")[i].Y, PathStorage.Load("Colection1")[i].Z);
            }
            GenericList<int> LIST = new GenericList<int>();
            LIST.Insert(51, 2);
            LIST.Insert(51, 1);
            LIST.Insert(51, 3);
            LIST.Insert(51, 3);
            LIST.AddElement(111);

            Console.WriteLine(LIST.Access(8));
            Console.WriteLine("ss"+LIST.array.Length + "Golemina na masiva");
            Console.WriteLine(LIST.Find(111));
            Console.WriteLine(LIST.Min() + " Min");
            Console.WriteLine(LIST.Max() + " Max");
            LIST.ClearArray();
            Console.WriteLine(LIST.Access(4));

            Matrix<int> matrix = new Matrix<int>(5,5);
            matrix.Add(1,1,5);
            matrix[1, 1] = 5;

            Console.WriteLine(matrix[1, 1]);
        }
开发者ID:smihaylovit,项目名称:TelerikHomework,代码行数:36,代码来源:Program.cs

示例11: Main

        private static void Main()
        {
            // Points
            Point3D.Z = 12;
            Console.WriteLine(Point3D.Z);
            Console.WriteLine(Point3D.PointO);
            double betweenTwoPoints = StaticClass.DistanceBetweenTwoPoints();
            Console.WriteLine(betweenTwoPoints);

            Path testingPath = new Path(12.32);
            testingPath.AddPointAndPrintAllPoints(12.12);
            PathStorage.AddPoints("123 123 123");
            PathStorage.ReadPoints();

            // Generic list
            var list = new GenericList<int>(1);

            // Resizeing
            Console.WriteLine(list.Length);
            list.Add(1);
            list.Add(2);
            Console.WriteLine(list.Length);
            list.Add(-2);
            Console.WriteLine(list.Length);
            list.Add(2);
            Console.WriteLine(list.Length);
            list.Add(122);
            Console.WriteLine(list.Length);

            // Max and min
            var max = list.Max();
            Console.WriteLine(max);
            var min = list.Min();
            Console.WriteLine(min);

            // Removes 3
            list.RemoveAt(2);
            Console.WriteLine();

            // Inserting at position
            list.InsertAt(0, 133);

            // Printing
            for (int i = 0; i < list.Length; i++)
            {
                Console.WriteLine(list[i]);
            }

            // To String
            Console.WriteLine();
            string toString = list.ToString();
            Console.WriteLine(toString);

            // Empty the array
            Console.WriteLine();
            list.Clear();
            for (int i = 0; i < list.Length; i++)
            {
                Console.WriteLine(list[i]);
            }

            list.Add(1);
            list.Add(2);
            list.Add(3);

            // FindingIndex
            Console.WriteLine();
            var find = list.IndexOf(2);
            Console.WriteLine(find);

            // Testing the matrix
            var matrixOne = new Matrix<int>(3, 3);
            matrixOne.Add(1);
            matrixOne.Add(1);
            matrixOne.Add(1);
            matrixOne.Add(1);
            var matrixTwo = new Matrix<int>(3, 3);
            matrixTwo.Add(2);
            matrixTwo.Add(2);
            matrixTwo.Add(2);
            matrixTwo.Add(2);
            var newMatrix = matrixOne + matrixTwo;
            for (int row = 0; row < 3; row++)
            {
                for (int col = 0; col < 3; col++)
                {
                    // if you change the 0 to any other number or whatever the if below will return true
                    newMatrix[row, col] = 0;
                    Console.Write(newMatrix[row, col] + " ");
                }

                Console.WriteLine();
            }

            if (newMatrix)
            {
                Console.WriteLine("The matrix statement is true");
            }
        }
开发者ID:DanteSparda,项目名称:TelerikAcademy,代码行数:99,代码来源:TestingAll.cs

示例12: GetSVDRotation

        protected double GetSVDRotation(Matrix<double>[] p1, Matrix<double>[] p2, out Matrix<double> rotation)
        {
            var centr1 = GetCentroid(p1);
            var centr2 = GetCentroid(p2);

            var q1 = new List<Matrix<double>>();
            var q2 = new List<Matrix<double>>();
            var H = new Matrix<double>(3, 3);

            for (int i = 0; i < Math.Min(p1.Count(), p2.Count()); ++i)
            {
                var q1d = new Matrix<double>(new double[,]
                {
                    {p1[i][0, 0] - centr1[0, 0]},
                    {p1[i][1, 0] - centr1[1, 0]},
                    {p1[i][2, 0] - centr1[2, 0]}
                });

                q1.Add(q1d);

                var q2d = new Matrix<double>(new double[,]
                {
                    {p2[i][0, 0] - centr2[0, 0]},
                    {p2[i][1, 0] - centr2[1, 0]},
                    {p2[i][2, 0] - centr2[2, 0]}
                });

                q2.Add(q2d);

                H = H.Add(q1d.Mul(q2d.Transpose()));
            }

            var U = new Matrix<double>(3, 3);
            var W = new Matrix<double>(3, 3);
            var V = new Matrix<double>(3, 3);

            CvInvoke.cvSVD(H, W, U, V, SVD_TYPE.CV_SVD_DEFAULT);

            var X = V.Mul(U.Transpose());

            var detX = CvInvoke.cvDet(X);

            rotation = X;
            return detX;
        }
开发者ID:JimmHub,项目名称:odoStuff,代码行数:45,代码来源:VisualOdometer.cs

示例13: button5_Click

 private void button5_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
     var fileName = openFileDialog1.FileName;
     try
     {
         using (var reader = File.OpenText(fileName))
         {
             var n = 0;
             var m = new Matrix<decimal>();
             var a = new Matrix<decimal>();
             var b = new Matrix<decimal>();
             var f = new Matrix<decimal>();
             var w = new Matrix<decimal>();
             for (var line = reader.ReadLine(); !string.IsNullOrWhiteSpace(line); line = reader.ReadLine())
             {
                 var arr = line.Split(' ');
                 if (arr[0][0] == 'N')
                 {
                     n = Convert.ToInt32(arr[1]);
                 }
                 else
                 {
                     var x = new Vector<decimal>();
                     for (var i = 1; i < arr.Length; i++) x.Add(Convert.ToDecimal(arr[i]));
                     if (arr[0][0] == 'M') m.Add(x);
                     if (arr[0][0] == 'A') a = new Matrix<decimal> {x};
                     if (arr[0][0] == 'B') b = new Matrix<decimal> {x};
                     if (arr[0][0] == 'F') f.Add(x);
                     if (arr[0][0] == 'W') w.Add(x);
                 }
             }
             numericUpDown1.Value = n;
             _matrixControlM.Value = m;
             _matrixControlA.Value = a;
             _matrixControlB.Value = b;
             _matrixControlF.Value = f;
             _matrixControlW.Value = w;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
开发者ID:dprotopopov,项目名称:nonlinear,代码行数:45,代码来源:OptionsForm.cs

示例14: AlignedROIs

        /// <summary>
        /// This method returns the 2 ROIs that are more "aligned", i.e. with the
        /// lowest difference in the Y coordinate
        /// It calculates the distances between all the ROIs and selects the appropriate pair
        /// </summary>
        /// <param name="ROIs"></param>
        /// <returns></returns>
        private MCvAvgComp[] AlignedROIs(MCvAvgComp[] ROIs)
        {
            MCvAvgComp[] alignedROIs = new MCvAvgComp[2];
            int N = ROIs.Length;
            Matrix<int> distancesY = new Matrix<int>(N, N);
            distancesY = distancesY.Add(100000);
            double minimum;
            double maximum;
            Point minimumLocation;
            Point maximumLocation;

            for (int i = 0; i < N; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    // If both rectangles do not intersect, we add their distance to the matrix
                    // MT: Min distance of 2 x roi.width
                    if (ROIs[j].rect.IntersectsWith(ROIs[i].rect) == false && Math.Abs(ROIs[j].rect.X - ROIs[i].rect.X) > ROIs[j].rect.Width*2.5)
                        distancesY[i, j] = Math.Abs(ROIs[j].rect.Y - ROIs[i].rect.Y);
                }
            }

            distancesY.MinMax(out minimum, out maximum, out minimumLocation, out maximumLocation);

            alignedROIs[0] = ROIs[minimumLocation.X];
            alignedROIs[1] = ROIs[minimumLocation.Y];

            return alignedROIs;
        }
开发者ID:jonbyte,项目名称:EyeSpark,代码行数:36,代码来源:EyeTracker.cs

示例15: BuildForwardWeightingMap

        /// <summary>
        /// Build the weighting maps
        /// </summary>
        private void BuildForwardWeightingMap()
        {
            // All goal weightings
            staticForwardCrateWeighting = new Matrix(goalMap,55f);

            // Corner goals get another 10
            Bitmap cornerGoals = goalMap.BitwiseAND(cornerMap);
            staticForwardCrateWeighting = staticForwardCrateWeighting.Add(new Matrix(cornerGoals, 33f));

            staticForwardCrateWeighting = staticForwardCrateWeighting.Average(boundryMap);

            // No crates will ever get onto a dead piece, but this will make the area around a dead cell less likely to be filled by crates
            staticForwardCrateWeighting = staticForwardCrateWeighting.Add(new Matrix(deadMap, -5f));

            // Player map
            staticPlayerRating = new Matrix(controller.Map.Size);

            // Leave the plaer map at zero for now
        }
开发者ID:rfrfrf,项目名称:SokoSolve-Sokoban,代码行数:22,代码来源:StaticAnalysis.cs


注:本文中的System.Matrix.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。