當前位置: 首頁>>代碼示例>>C#>>正文


C# Matrix.PrintMatrix方法代碼示例

本文整理匯總了C#中System.Matrix.PrintMatrix方法的典型用法代碼示例。如果您正苦於以下問題:C# Matrix.PrintMatrix方法的具體用法?C# Matrix.PrintMatrix怎麽用?C# Matrix.PrintMatrix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Matrix的用法示例。


在下文中一共展示了Matrix.PrintMatrix方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        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");
            }
           
        }
開發者ID:RRRRRRRRRR,項目名稱:thegodmode.github.com,代碼行數:54,代碼來源:TestMatrix.cs

示例2: Main

        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();
        }
開發者ID:monikaBchvarova,項目名稱:C-Sharp,代碼行數:88,代碼來源:Test.cs

示例3: Main

        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));
        }
開發者ID:monikaBchvarova,項目名稱:C-Sharp,代碼行數:95,代碼來源:MatrixTest.cs


注:本文中的System.Matrix.PrintMatrix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。