Example #1
0
        public override void CalculateMatrix(int[,] matrix1, int[,] matrix2)
        {
            var Filling = new CreateMarixes();

            base.CalculateMatrix(matrix1, matrix2);

            int[,] result = new int[matrix1.GetLength(0), matrix2.GetLength(1)];

            for (int i = 0; i < matrix1.GetLength(0); i++)
            {
                for (int j = 0; j < matrix2.GetLength(1); j++)
                {
                    for (int k = 0; k < matrix1.GetLength(1); k++)
                    {
                        result[i, j] += matrix1[i, k] * matrix2[k, j];
                    }
                }
            }
            Filling.Print(result);
        }
Example #2
0
        public void MatrixGO()
        {
            var IManage = new IManager();
            var Filling = new CreateMarixes();

            int[,] C;

            bool           toContinue    = true;
            List <int[, ]> Matrixhistory = new List <int[, ]>();

            while (toContinue)
            {
                IManage.PrintLn("\n1.Start work wit matrixes   \t2.back to the Main menu ");
                IManage.PrintChoose();
                try
                {
                    int command = Convert.ToInt32(Console.ReadLine());

                    switch (command)
                    {
                    case 1:

                        var M1 = new MatrixCl();
                        M1.row    = Filling.GetSize(" row matrix 1 ");
                        M1.column = Filling.GetSize(" column matrix 1  ");
                        M1.matrix = new int[M1.row, M1.column];

                        var M2 = new MatrixCl();
                        M2.row = Filling.GetSize(" row matrix 1 ");
                        // while (M1.matrix.GetLength(1) != M2.matrix.GetLength(0))
                        while (M1.column != M2.row)
                        {
                            IManage.PrintLn("collumns 1Matrix must be = rows 2Matrix");
                            M2.row = Filling.GetSize(" row matrix 1 ");
                        }
                        M2.column = Filling.GetSize(" column matrix 1  ");
                        M2.matrix = new int[M2.row, M2.column];

                        IManage.PrintLn("fill matrix 1 ");
                        M1.matrix = Filling.FillMatrix(M1.row, M1.column);
                        Filling.Print(M1.matrix);

                        IManage.PrintLn("fill matrix 2 ");
                        M2.matrix = Filling.FillMatrix(M2.row, M2.column);
                        Filling.Print(M2.matrix);


                        var MatrixResult = new MatrixMultiply();
                        MatrixResult.CalculateMatrix(M1.matrix, M2.matrix);
                        //How i can set matrix as the first need to look how to transporent it
                        //  Matrixhistory.Add(MatrixResult.result);
                        Matrixhistory.Add(MatrixResult.result);
                        M1.matrix = MatrixResult.result;
                        //Matrixhistory.Add(M1.matrix);
                        break;

                    case 2:
                        toContinue = false;
                        continue;
                    }
                    foreach (int[,] recordM in Matrixhistory)
                    {
                        int a = Matrixhistory.LastIndexOf(recordM);
                        a++;
                        IManage.PrintLn($"\n record N  {a} was created {DateTime.Now}");
                    }
                    IManage.PrintLn($"\n\tDo you want use result ? " +
                                    "\nfor use result enter 'U' \tfor start work with numbers press something\n");
                    if (Console.ReadKey().Key == ConsoleKey.U)
                    {
                        continue;
                    }
                    else
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    IManage.PrintLn("\n");
                    IManage.PrintLn(ex.Message);
                }
            }
        }