Пример #1
0
        static void Main()
        {
            int row = 4, col = 5;
            var matrixOne = new Matrix<int>(row, col);
            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    matrixOne[r, c] = r + c;
                }
            }

            Console.WriteLine("Matrix One:");
            Console.WriteLine(matrixOne.ToString());

            var matrixTwo = new Matrix<int>(row, col);
            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    matrixTwo[r, c] = (r + c) * 2;
                }
            }

            Console.WriteLine("Second matrix:");
            Console.WriteLine(matrixOne.ToString());

            var sum = matrixOne + matrixTwo;
            Console.WriteLine($"Sum: \n{sum.ToString()}");
            var minus = matrixOne - matrixTwo;
            Console.WriteLine($"Minus:\n {minus.ToString()}");
            var multy = matrixOne * matrixTwo;
            Console.WriteLine($"Multy: \n{multy.ToString()}");
        }
Пример #2
0
 public static string DumpMatrixString(Matrix matrix)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("==");
     Label_0076:
     builder.Append(matrix.ToString());
     builder.Append("==\n");
     int num = 0;
     Label_001E:
     if (num < matrix.Rows)
     {
         builder.Append("  [");
         for (int i = 0; i < matrix.Cols; i++)
         {
             if (i != 0)
             {
                 builder.Append(",");
             }
             builder.Append(matrix[num, i]);
         }
     }
     else
     {
         return builder.ToString();
     }
     if (0 == 0)
     {
         builder.Append("]\n");
         num++;
         goto Label_001E;
     }
     goto Label_0076;
 }
Пример #3
0
        static void Main(string[] args)
        {
            //Create two matrices
            Matrix<int> mat1 = new Matrix<int>(3, 5);
            Matrix<int> mat2 = new Matrix<int>(3, 5);

            //Fill the matrices with numbers
            for (int i = 0; i < mat1.Rows; i++)
            {
                for (int j = 0; j < mat1.Cols; j++)
                {
                    mat1.AddNumber(i + j, i, j);
                }
            }
            for (int i = 0; i < mat1.Rows; i++)
            {
                for (int j = 0; j < mat1.Cols; j++)
                {
                    mat2[i, j] = i + j;
                }
            }

            //Print them
            Console.WriteLine(mat1.ToString());
            Console.WriteLine(mat2.ToString());

            //Use predefined operators and print the result
            Console.WriteLine((mat1 + mat2).ToString());
            Console.WriteLine((mat1 - mat2).ToString());
            //Console.WriteLine((mat2*mat2).ToString()); //For multiplication we need the row on the first matrix and col on the second matrix to be equal
            Console.WriteLine(mat1==mat2);
        }
Пример #4
0
        static void Main()
        {
            //create instance of matixT
            Matrix<int> matrix1 = new Matrix<int>(3, 3);
            Matrix<int> matrix2 = new Matrix<int>(3, 3);

            //Fill in with numbers
            for (int i = 0; i < matrix1.Rows; i++)
            {
                for (int j = 0; j < matrix1.Cols; j++)
                {
                    matrix1.AddNumber(i + j, i, j);
                }
            }
            for (int i = 0; i < matrix1.Rows; i++)
            {
                for (int j = 0; j < matrix1.Cols; j++)
                {
                    matrix2[i, j] = i + j;
                }
            }

            //Print to view the starting point
            Console.WriteLine(matrix1.ToString());
            Console.WriteLine(matrix2.ToString());

            //test operators
            Console.WriteLine("operator + :");
            Console.WriteLine((matrix1 + matrix2).ToString());
            Console.WriteLine("operator - :");
            Console.WriteLine((matrix1 - matrix2).ToString());

            //check for equality
            Console.WriteLine(matrix1 == matrix2);
        }
        public void TwoSizedMatrixTest()
        {
            Matrix matrix = new Matrix(2);

            Assert.IsTrue(matrix.ToString() == string.Format("    1    4\r\n"+
                                                             "    3    2"));
        }
        static void Main()
        {
            Matrix<int> testMatrix1 = new Matrix<int>(new int[2,3]{{1,2,3},{4,5,6}});
            Matrix<int> testMatrix2 = new Matrix<int>(new int[3,2] { {7,8}, {9,10},{11,12} });
            Matrix<int> testMatrix3 = new Matrix<int>(new int[3, 3] { { 1, 2, 3 }, { 4, 5, 6 }, {7,8,9}});
            Matrix<int> testMatrix4 = new Matrix<int>(new int[3, 3] { { 1, 2, 3 }, { 4, 5, 6 }, {7,8,9} });

            //Multiply
            Console.WriteLine("Matrix 1:");
            Console.WriteLine(testMatrix1.ToString());

            Console.WriteLine("Matrix 2:");
            Console.WriteLine(testMatrix2.ToString());
            Console.WriteLine("Multiplication:");
            Console.WriteLine((testMatrix1 * testMatrix2).ToString());

            //Addition/ Substraction
            Console.WriteLine("Matrix 3:");
            Console.WriteLine(testMatrix3.ToString());

            Console.WriteLine("Matrix 4:");
            Console.WriteLine(testMatrix4.ToString());

            Console.WriteLine("Addition Matrix 3 + Matrix4:");
            Console.WriteLine((testMatrix3 + testMatrix4).ToString());

            Console.WriteLine("Substraction MAtrix3 - Matrix4:");
            Console.WriteLine((testMatrix3 - testMatrix4).ToString());

            //Indexer
            Console.WriteLine("Matrix3[2,2]:{0}",testMatrix3[2,2]);
        }
        public Presence[] GetPresence(string from, string to, Matrix.Xmpp.PresenceType? type, bool remove)
        {
            List<Presence> presences = new List<Presence>();
            var db = GetDatabase();
            var collection = db.GetCollection("offline_presence");
            var query = new QueryDocument();
            if (from != null)
                query.Add("from", from);
            if (to != null)
                query.Add("to", to);
            if (type != null)
                query.Add("type", type.ToString());

            MongoCursor<BsonDocument> cursor;
            if (from == null && to == null)
                cursor = collection.FindAll();
            else
                cursor = collection.Find(query);

            foreach (var item in cursor)
            {
                Presence presence = (Presence)Presence.LoadXml(item.GetValue("value").AsString);
                presences.Add(presence);
            }
            if (remove)
                collection.Remove(query);
            return presences.ToArray();
        }
 public void TestMatrixToString()
 {
     Matrix matrix = new Matrix(2);
     string expected = string.Format(
         "  1  4" + Environment.NewLine +
         "  3  2" + Environment.NewLine);
     Assert.AreEqual(expected, matrix.ToString());
 }
Пример #9
0
        static void Main(string[] args)
        {
            Matrix<int> test = new Matrix<int>(2, 2);
            test.GetCol(3);
            
            Console.WriteLine(test.ToString());

        }
Пример #10
0
        public void ThreeSizedMatrixTest()
        {
            Matrix matrix = new Matrix(3);

            Assert.IsTrue(matrix.ToString() == string.Format("    1    7    8\r\n" +
                                                             "    6    2    9\r\n" +
                                                             "    5    4    3"));
        }
Пример #11
0
        public void TestMatrixToString()
        {
            Matrix matrix = new Matrix(3);

            string expected = "0 0 0\n0 0 0\n0 0 0\n";
            string actual = matrix.ToString();

            Assert.AreEqual(expected, actual);
        }
Пример #12
0
        static void Main()
        {
            // Creating two matrices to be tested
            Matrix<int> firstMatrix = new Matrix<int>(3, 4);
            Console.WriteLine("First Matrix Capacity is {0}\n", firstMatrix.Capacity);

            Matrix<int> secondMatrix = new Matrix<int>(3, 4);

            FillMatrixWithInt(firstMatrix);
            Console.WriteLine("First Matrix:");
            Console.WriteLine(firstMatrix.ToString());

            FillMatrixWithInt(secondMatrix);
            Console.WriteLine("Second Matrix:");
            Console.WriteLine(secondMatrix.ToString());

            // test operator +
            firstMatrix += secondMatrix;
            Console.WriteLine("Applying the operator +");
            Console.WriteLine(firstMatrix.ToString());

            // test operator -
            firstMatrix -= secondMatrix;
            Console.WriteLine("Applying the operator -");
            Console.WriteLine(firstMatrix.ToString());

            // test operator *
            firstMatrix *= secondMatrix;
            Console.WriteLine("Applying the operator *");
            Console.WriteLine(firstMatrix.ToString());

            // test method bool
            Matrix<double> testBool = new Matrix<double>(1, 1);
            testBool[0, 0] = 0.0;
            if (testBool)
            {
                Console.WriteLine("testBool does not contain Zero");
            }
            else
            {
                Console.WriteLine("testBool contains Zero");
            }
            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            Matrix<int> matrix1 = new Matrix<int>(5, 5);
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 5; j++)
                {
                    matrix1[i, j] = i * j;
                }
            }

            Matrix<int> matrix2 = new Matrix<int>(5, 5);
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 5; j++)
                {
                    matrix2[i, j] = i * j;
                }
            }

            int el = matrix1[2, 2];
            Console.WriteLine("matrix1[2, 2]: {0}", el);
            Console.WriteLine("matrix1:");
            Console.WriteLine(matrix1.ToString());
            Console.WriteLine("matrix2: ");
            Console.WriteLine(matrix2.ToString());

            Matrix<int> matrixMultiplied = new Matrix<int>(5, 5);
            matrixMultiplied = matrix1 * matrix2;
            Console.WriteLine("matrix1 * matrix2:");
            Console.WriteLine(matrixMultiplied.ToString());

            Matrix<int> matrixAddition = new Matrix<int>(5, 5);
            matrixAddition = matrix1 + matrix2;
            Console.WriteLine("matrix1 + matrix2:");
            Console.WriteLine(matrixAddition.ToString());

            Matrix<int> matrixSubtract = new Matrix<int>(5, 5);
            matrixAddition = matrix1 + matrix2;
            Console.WriteLine("matrix1 - matrix2:");
            Console.WriteLine(matrixSubtract.ToString());

            Matrix<int> m = new Matrix<int>(2, 2);
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    m[i, j] = 1;
                }
            }
            if (m)
            {
                Console.WriteLine("m have no element with value 0");
            }
        }
Пример #14
0
        public void SixSizedMatrixTest()
        {
            Matrix matrix = new Matrix(6);

            Assert.IsTrue(matrix.ToString() == string.Format("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}",
                "    1   16   17   18   19   20",
                "   15    2   27   28   29   21",
                "   14   31    3   26   30   22",
                "   13   36   32    4   25   23",
                "   12   35   34   33    5   24",
                "   11   10    9    8    7    6"));
        }
Пример #15
0
 static void Main()
 {
     Matrix<double> test = new Matrix<double>(2, 2);
     test[1, 1] = 2.4;
     Console.WriteLine(test.ToString());
     Matrix<string> anotherTest = new Matrix<string>(3, 3);
     anotherTest[0, 0] = "The";
     anotherTest[1, 0] = "has";
     anotherTest[0, 1] = "Matrix";
     anotherTest[1, 1] = "you";
     Console.WriteLine(anotherTest.ToString());
 }
Пример #16
0
        public void MatrixShouldFillCorrectly()
        {
            Matrix testMatrix = new Matrix(6);
            string expected = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}\r\n",
                "  1 16 17 18 19 20",
                " 15  2 27 28 29 21",
                " 14 31  3 26 30 22",
                " 13 36 32  4 25 23",
                " 12 35 34 33  5 24",
                " 11 10  9  8  7  6");


            Assert.AreEqual(testMatrix.ToString(), expected);
        }
Пример #17
0
        public void MatrixToStringShouldProduceExpectedOutputForAValidMatrix()
        {
            Matrix testMatrix = new Matrix(5);
            StringBuilder expected = new StringBuilder();
            for (int i = 0; i < testMatrix.Field.GetLength(0); i++)
            {
                for (int j = 0; j < testMatrix.Field.GetLength(0); j++)
                {
                    expected.AppendFormat("{0,3}", testMatrix.Field[i, j]);
                }

                expected.Append(Environment.NewLine);
            }

            Assert.AreEqual(testMatrix.ToString(), expected.ToString());
        }
Пример #18
0
        static void Main(string[] args)
        {
            Matrix<int> myMatrix = new Matrix<int>(2,2);
            Matrix<int> yourMatrix = new Matrix<int>(2, 2);
            myMatrix[0, 0] = 1;
            myMatrix[0, 1] = 2;
            myMatrix[1, 0] = 3;
            myMatrix[1,1] = 4;

            yourMatrix[0, 0] = 1;
            yourMatrix[0, 1] = 2;
            yourMatrix[1, 0] = 3;
            yourMatrix[1, 1] = 4;

            Console.WriteLine(myMatrix.ToString());
            Console.WriteLine(yourMatrix.ToString());
            //test addition of two matrices
            Console.WriteLine((myMatrix + yourMatrix).ToString());
            //test subtraction of thwo matrices
            Console.WriteLine((myMatrix - yourMatrix).ToString());

            Matrix<int> firstMatrix = new Matrix<int>(3, 2);
            Matrix<int> secondMatrix = new Matrix<int>(2, 2);
            firstMatrix[0, 0] = 1;
            firstMatrix[0, 1] = 3;
            firstMatrix[1, 0] = 0; //default of (int)
            firstMatrix[1, 1] = -2;
            firstMatrix[2, 0] = 4;
            firstMatrix[2, 1] = 1;

            secondMatrix[0, 0] = 7;
            secondMatrix[0, 1] = 9;
            secondMatrix[1, 0] = 5;
            secondMatrix[1, 1] = 2;

            Console.WriteLine((firstMatrix*secondMatrix).ToString());

            //test the true/false operator
            if (firstMatrix)
            {
                Console.WriteLine(true);
            }
            else
            {
                Console.WriteLine(false);
            }
        }
        public void MatrixToStringShouldProduceExpectedOutputForAValidMatrix()
        {
            var size = 5;
            var matrix = new Matrix(size);
            StringBuilder expected = new StringBuilder();
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    expected.AppendFormat("{0,4}", matrix.Field[i, j]);
                }

                expected.Append(Environment.NewLine);
            }

            Assert.AreEqual(matrix.ToString(), expected.ToString());
        }
Пример #20
0
        public static void Run()
        {
            var firstMatrix = new Matrix<int>(2, 2);
            firstMatrix[0, 0] = 1;
            firstMatrix[0, 1] = 2;
            firstMatrix[1, 0] = 3;
            firstMatrix[1, 1] = 4;

            var secondMatrix = new Matrix<int>(2, 2);

            secondMatrix[0, 0] = 5;
            secondMatrix[0, 1] = 6;
            secondMatrix[1, 0] = 7;
            secondMatrix[1, 1] = 8;

            Console.WriteLine("First matrix: ");
            Console.WriteLine(firstMatrix.ToString());
            Console.WriteLine("Second matrix: ");
            Console.WriteLine(secondMatrix.ToString());

            Console.WriteLine("First matrix + Second matrix: ");
            Console.WriteLine((firstMatrix + secondMatrix).ToString());

            Console.WriteLine("First matrix - Second matrix: ");
            Console.WriteLine((firstMatrix - secondMatrix).ToString());

            Console.WriteLine("First matrix * Second matrix: ");
            Console.WriteLine((firstMatrix * secondMatrix).ToString());

            Console.WriteLine("The value at position [1, 0] in the first matrix is {0}", firstMatrix[1,0]);
            Console.WriteLine();
            Console.WriteLine("The matrixes have {0} rows and {1} columns", firstMatrix.Rows, firstMatrix.Columns);
            Console.WriteLine();

            var zeroMatrix = new Matrix<int>(1, 1);
            secondMatrix[0, 0] = 0;
            secondMatrix[0, 1] = 0;

            Console.WriteLine(firstMatrix ? "First matrix is a zero matrix" : "First matrix is a non-zero matrix");
            Console.WriteLine(zeroMatrix ? "Zero matrix is a zero matrix" : "Zero matrix is a non-zero matrix");
            Console.WriteLine();
        }
Пример #21
0
 /// <summary>
 /// Dump a matrix to a string.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 /// <returns>The matrix as a string.</returns>
 public static String DumpMatrixString(Matrix matrix)
 {
     var result = new StringBuilder();
     result.Append("==");
     result.Append(matrix.ToString());
     result.Append("==\n");
     for (int row = 0; row < matrix.Rows; row++)
     {
         result.Append("  [");
         for (int col = 0; col < matrix.Cols; col++)
         {
             if (col != 0)
             {
                 result.Append(",");
             }
             result.Append(matrix[row, col]);
         }
         result.Append("]\n");
     }
     return result.ToString();
 }
        public void TestToString()
        {
            int[,] data = new int[6, 6]
            {
                {1, 1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1, 1}
            };
            Matrix matrix = new Matrix(6, data);
            string expected = "  1  1  1  1  1  1\n" +
                            "  1  1  1  1  1  1\n" +
                            "  1  1  1  1  1  1\n" +
                            "  1  1  1  1  1  1\n" +
                            "  1  1  1  1  1  1\n" +
                            "  1  1  1  1  1  1\n";

            Assert.AreEqual(expected, matrix.ToString());
        }
Пример #23
0
        public static void Main()
        {
            Matrix a = new Matrix(4, 6);
            Matrix b = new Matrix(4, 6);
            Matrix c = new Matrix(6, 2);

            for (int i = 0; i < a.Rows; i++)
            {
                for (int j = 0; j < a.Cols; j++)
                {
                    a[i, j] = (1 * j) + (2 * i);
                    b[i, j] = (5 * j) + (i * 3);
                }
            }

            for (int i = 0; i < c.Rows; i++)
            {
                for (int j = 0; j < c.Cols; j++)
                {
                    c[i, j] = (7 * j) + (2 * i);
                }
            }

            Console.WriteLine(a.ToString());
            Console.WriteLine(separator);
            Console.WriteLine(b.ToString());
            Console.WriteLine(separator);
            Console.WriteLine(c.ToString());
            Console.WriteLine(separator);

            Console.WriteLine((a + b).ToString());
            Console.WriteLine(separator);
            Console.WriteLine((a - b).ToString());
            Console.WriteLine(separator);
            Console.WriteLine((a * c).ToString());
            Console.WriteLine(separator);
            Console.WriteLine((b * c).ToString());
        }
Пример #24
0
		private void test7TrasfoToolStripMenuItem_Click(object sender, EventArgs e)
			{
			Matrix A = new Matrix(3,3);
			A.Set(0,0,1);
			A.Set(0,1,2);
			A.Set(0,2,3);
			A.Set(1,0,4);
			A.Set(1,1,5);
			A.Set(1,2,6);
			A.Set(2,0,7);
			A.Set(2,1,8);
			A.Set(2,2,9);

			Matrix B = new Matrix(3,2);
			B.Set(0,0,1);
			B.Set(0,1,0);
			B.Set(1,0,-1);
			B.Set(1,1,2);
			B.Set(2,0,0);
			B.Set(2,1,1);
			Matrix C = A*B;
			Matrix D = B*A;
			MessageBox.Show("A=\n" + A.ToString());
			MessageBox.Show("B=\n" + B.ToString());
			MessageBox.Show("C=\n" + C.ToString());
			MessageBox.Show("D=\n" + D.ToString());

			Point2D p1 = new Point2D(10,5);
			MessageBox.Show("p1=\n" + p1.ToString());

			Transform2D tr;
			Transform2D t1 = Transform2D.Traslazione(100,-200);
			Transform2D t2 = Transform2D.Traslazione(-10,-20);
			tr = t1 + t2;	// Combinazione di trasformazioni
			MessageBox.Show("tr=\n" + tr.ToString());

			Matrix h**o = Transform2D.Convert(p1);
			MessageBox.Show("h**o=\n" + h**o.ToString());

			Point2D p2 = Transform2D.Convert(h**o);
			MessageBox.Show("p2=\n" + p2.ToString());

			Point2D p3 = tr.Transform(p1);
			MessageBox.Show("p3=\n" + p3.ToString());

			Transform2D rot = Transform2D.Rotazione(20,false);
			Transform2D tra = Transform2D.Traslazione(100,0);

			Transform2D rot_tra = rot + tra;
			Transform2D tra_rot = tra + rot;

			Point2D p0 = new Point2D(0,0);
			rot_tra.Transform(p0);

			MessageBox.Show(p0 + " rotXtra\n" + rot_tra.Transform(p0));
			MessageBox.Show(p0 + " traXrot\n" + tra_rot.Transform(p0));

			#pragma warning disable
			int tmp;
			tmp = 1;
			#pragma warning restore
			}
Пример #25
0
 public void TestMatrixWithSize4ShouldReturnCorrectResult()
 {
     var matrix = new Matrix(4);
     Assert.AreEqual(matrix.ToString(), MatrixWithSize4);
 }
Пример #26
0
 public void TestMatrixWithSize3ShouldReturnCorrectResult()
 {
     var m = new Matrix(3);
     Assert.AreEqual(m.ToString(), Matrix3Elements);
 }
Пример #27
0
        public static void MainMath2()
        {
            Matrix m;

            m = new Matrix(2, 2);
            m[0, 0] = 0;
            m[0, 1] = -1;
            m[1, 0] = 1;
            m[1, 1] = 0;
            Console.WriteLine(m.ToString());
            Console.WriteLine("Determinant");
            Console.WriteLine(m.Determinant);

            m = new Matrix(4, 4);
            m[0, 0]= 0;
            m[0, 1]= -1;
            m[0, 2]= 0;
            m[0, 3]= 10;
            m[1, 0]= 1;
            m[1, 1]= 0;
            m[1, 2]= 0;
            m[1, 3]= 5;
            m[2, 0]= 0;
            m[2, 1]= 0;
            m[2, 2]= 1;
            m[2, 3]= 0;
            m[3, 0]= 0;
            m[3, 1]= 0;
            m[3, 2]= 0;
            m[3, 3]= 1;

            Console.WriteLine(m.ToString());
            Console.WriteLine("Invert");
            Console.WriteLine(m.Inverse.ToString());

            m = Matrix.Identity(4);
            Vector4 v4 = new Vector4(1, 2, 3, 4);
            Vector4 result = (Vector4) (v4 * m);
            Console.WriteLine(result.ToString());
            result = (Vector4)(m * v4);
            Console.WriteLine(result.ToString());
        }
Пример #28
0
 public void PrintMatrix(Matrix matrix, string name)
 {
     txb_result.Text += name + ":\r\n";
     txb_result.Text += matrix.ToString();
     txb_result.Text += "\r\n";
 }
Пример #29
0
 public void WriteMatrix()
 {
     var matrix1 = new Matrix(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
     const string MatrixString = "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15";
     Assert.AreEqual(MatrixString, matrix1.ToString());
 }
Пример #30
0
        public void OneSizedMatrixTest()
        {
            Matrix matrix = new Matrix(1);

            Assert.IsTrue(matrix.ToString() == string.Format("    1"));
        }