예제 #1
0
        // get matrix (n^2 size ! , 1-s on main diagonal 0 elsewhere), multiply with itself, if result is identical to original TRUE, else FALSE.
        public static void IsIdentity(int[,] inMatrix)
        {
            string askIsIt = "\nIs The Matrix likely to be an \"Identity Matrix\"?";
            int    idRows = inMatrix.GetLength(0);  int idCols = inMatrix.GetLength(1);

            int[,] identity = new int[idRows, idCols];
            double s = Math.Sqrt(idRows * idCols);

            Console.WriteLine($"-------------------------\n" +
                              "Identity Matrix check\n----------\n" +
                              $"Row length (nr. of columns): {idCols}\n" +
                              $"Column length (nr. of rows): {idRows}\n" +
                              $"This one's square root: {s}");

            // FIRST - an IM is a matrix with equal length rows and columns.
            if (idRows == s && idCols == s)
            {
                Console.Write($"{askIsIt}  May be {true}.");

                // SECOND - an IM on the power of 2 (basically multiplied ONCE with itself) ia always identical to the one being evaluated!
                MakeIdentity(inMatrix, identity);

                Console.WriteLine("\n\nThe Matrix, Origins:");  SetPrint.PrintTheMatrix(inMatrix);

                Console.WriteLine("\nThe Matrix, Squared:");  SetPrint.PrintTheMatrix(identity);

                Console.WriteLine($"\nIs \"The Matrix\" an \"Identity Matrix\"?  {VerifyIdentity(inMatrix, identity)}.");
            }
            else
            {
                Console.Write($"{askIsIt}  Definitely {false}.\n" +
                              $"Such a matrix has to be square (equal length rows & columns) to even be considered.\n");
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            int    cols      = SetPrint.DefineTheMatrixLimits("Row length (nr. of columns) = ");
            int    rows      = SetPrint.DefineTheMatrixLimits("Column length (nr. of rows) = ");
            string askMatrix = "\n\tEnter The Matrix:\n--------------------------";

            int[,] theMatrix = new int[rows, cols];

            SetPrint.GetTheMatrix(askMatrix, theMatrix);
            SetPrint.PrintTheMatrix(theMatrix);

            GetDiagonal.FindSecondaryDiagonal(theMatrix);

            SetPrint.PrintTheMatrix(GetTransposed.TransposeMatrix(theMatrix));

            CheckIdentity.IsIdentity(theMatrix);

            Console.WriteLine("\nEnd.\n");
        }