static void Main(string[] args)
        {
            int[,] arr1 = {
                {1,2,3},
                {4,5,6}
                
            };

            int[,] arr2 = {
                {7,8},
                {9,10},
                {11,12},
            };

            double[,] arr3 = {
                {1.5,2.5,3.7},
                {4,5,6}
                
            };

            double[,] arr4 = {
                {7,8},
                {9,10},
                {11,12},
            };

            //string[,] arr5 = new string[20,20];

           /* int[,] arr2 = {    check true and false operators
                {0,0},
                {0,0},
                {0,0},
            };
            */
            
            Matrix<int> matrix = new Matrix<int>(arr1);
            Matrix<int> matrix1 = new Matrix<int>(arr2);
            Matrix<double> matrix2 = new Matrix<double>(arr3);
            Matrix<double> matrix3 = new Matrix<double>(arr4);
           // Matrix<string> matrix4 = new Matrix<string>(arr5);
            //matrix.printMatrix();
            matrix = matrix * matrix1;
            matrix2 = matrix2 * matrix3;
            if (matrix)
            {
                matrix.PrintMatrix();
                matrix2.PrintMatrix();
            }
            else
            {
                Console.WriteLine("Matrix has 0 Value");
            }
           
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var rows = 4;
            var cols = 4;
            var matrix = new Matrix<int>(rows, cols);

            var counter = 0;
            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < cols; col++)
                {
                    matrix[row, col] = counter++;
                }
            }

            var getRow = 1;
            var getCol = 1;
            matrix.PrintMatrix();
            Console.WriteLine("matrix[{0}, {1}] = {2}", getRow, getCol, matrix[1, 1]);

            var matrixOne = new Matrix<int>(2, 2);
            matrixOne[0, 0] = 1;
            matrixOne[0, 1] = 2;
            matrixOne[1, 0] = 3;
            matrixOne[1, 1] = 4;

            var matrixTwo = new Matrix<int>(2, 2);
            matrixTwo[0, 0] = 5;
            matrixTwo[0, 1] = 6;
            matrixTwo[1, 0] = 7;
            matrixTwo[1, 1] = 8;

            Console.WriteLine(new string('-', 10));

            Console.WriteLine("Matrix (a)");
            Console.WriteLine(new string('-', 10));

            matrixOne.PrintMatrix();
            Console.WriteLine(new string('-', 10));
            Console.WriteLine("Matrix (b)");
            Console.WriteLine(new string('-', 10));

            matrixTwo.PrintMatrix();
            Console.WriteLine(new string('=', 10));
            Console.WriteLine("Plus (a + b)");
            Console.WriteLine("Equals (=)");
            var matrixPlus = matrixOne + matrixTwo;
            matrixPlus.PrintMatrix();

            Console.WriteLine(new string('=', 10));
            Console.WriteLine("Minus (a - b)");
            Console.WriteLine("Equals (=)");
            var matrixMinus = matrixOne - matrixTwo;
            matrixMinus.PrintMatrix();

            // for more info:
            // http://www.mathsisfun.com/algebra/matrix-multiplying.html
            var mOne = new Matrix<int>(2, 3);
            mOne[0, 0] = 1;
            mOne[0, 1] = 2;
            mOne[0, 2] = 3;
            mOne[1, 0] = 4;
            mOne[1, 1] = 5;
            mOne[1, 2] = 6;

            var mTwo = new Matrix<int>(3, 2);
            mTwo[0, 0] = 7;
            mTwo[0, 1] = 8;
            mTwo[1, 0] = 9;
            mTwo[1, 1] = 10;
            mTwo[2, 0] = 11;
            mTwo[2, 1] = 12;

            Console.WriteLine(new string('-', 10));

            Console.WriteLine("Matrix (A)");
            mOne.PrintMatrix();
            Console.WriteLine(new string('-', 10));
            Console.WriteLine("Matrix (B)");
            mTwo.PrintMatrix();
            Console.WriteLine(new string('-', 10));

            Console.WriteLine(new string('=', 10));
            Console.WriteLine("Multiply (A * B)");
            Console.WriteLine("Equals (=)");
            var matrixMultiply = mOne * mTwo;
            matrixMultiply.PrintMatrix();
        }
        private static void Main(string[] args)
        {
            var matrixOne = new Matrix<int>(2, 2);
            matrixOne[0, 0] = 1;
            matrixOne[0, 1] = 2;
            matrixOne[1, 0] = 3;
            matrixOne[1, 1] = 4;

            var matrixTwo = new Matrix<int>(2, 2);
            matrixTwo[0, 0] = 0;
            matrixTwo[0, 1] = 6;
            matrixTwo[1, 0] = 7;
            matrixTwo[1, 1] = 8;

            Console.WriteLine(new string('-', 10));

            Console.WriteLine("Matrix (a)");
            Console.WriteLine(new string('-', 10));

            matrixOne.PrintMatrix();
            Console.WriteLine(new string('-', 10));
            Console.WriteLine("Matrix (b)");
            Console.WriteLine(new string('-', 10));

            matrixTwo.PrintMatrix();
            Console.WriteLine(new string('=', 10));
            Console.WriteLine("Plus (a + b)");
            Console.WriteLine("Equals (=)");
            var matrixPlus = matrixOne + matrixTwo;
            matrixPlus.PrintMatrix();

            Console.WriteLine(new string('=', 10));
            Console.WriteLine("Minus (a - b)");
            Console.WriteLine("Equals (=)");
            var matrixMinus = matrixOne - matrixTwo;
            matrixMinus.PrintMatrix();

            var mOne = new Matrix<int>(2, 3);
            mOne[0, 0] = 1;
            mOne[0, 1] = 2;
            mOne[0, 2] = 3;
            mOne[1, 0] = 4;
            mOne[1, 1] = 5;
            mOne[1, 2] = 6;

            var mTwo = new Matrix<int>(3, 2);
            mTwo[0, 0] = 7;
            mTwo[0, 1] = 8;
            mTwo[1, 0] = 9;
            mTwo[1, 1] = 10;
            mTwo[2, 0] = 11;
            mTwo[2, 1] = 12;

            Console.WriteLine(new string('-', 10));

            Console.WriteLine("Matrix (A)");
            mOne.PrintMatrix();
            Console.WriteLine(new string('-', 10));
            Console.WriteLine("Matrix (B)");
            mTwo.PrintMatrix();
            Console.WriteLine(new string('-', 10));

            Console.WriteLine(new string('=', 10));
            Console.WriteLine("Multiply (A * B)");
            Console.WriteLine("Equals (=)");
            var matrixMultiply = mOne*mTwo;
            matrixMultiply.PrintMatrix();

            Console.WriteLine(new string('=', 10));

            matrixOne.PrintMatrix();

            if (matrixOne)
            {
                Console.WriteLine("Matrix has ZERO value");
            }
            else
            {
                Console.WriteLine("Does NOT have ZERO value");
            }

            Console.WriteLine(new string('=', 10));

            matrixTwo.PrintMatrix();
            if (matrixTwo)
            {
                Console.WriteLine("Matrix has ZERO value");
            }
            else
            {
                Console.WriteLine("Does NOT have ZERO value");
            }

            Console.WriteLine(new string('=', 10));
        }