Example #1
0
        public MyMatrix Mult(MyMatrix m)
        {
            int start_timer, elapsed_time;

            start_timer = DateTime.Now.Millisecond;
            int counter = 0;

            if (y != m.X)
            {
                Console.WriteLine("Matrices not compatible. sorry");
                return(null);
            }

            MyMatrix res = new MyMatrix(x, m.Y);

            res.Init();

            for (int i = 0; i < res.Y; i++)
            {
                for (int j = 0; j < res.X; j++)
                {
                    int sum = 0;
                    for (int k = 0; k < x; k++)
                    {
                        sum     += matrix[k][i] + m.Matrix[j][k];
                        counter += 2;
                    }
                    counter++;
                }
                counter++;
            }
            elapsed_time = DateTime.Now.Millisecond - start_timer;
            Console.WriteLine("\nThis Operation took " + elapsed_time.ToString() + "and took " + counter.ToString() + " Steps");
            return(res);
        }
Example #2
0
        public MyMatrix Add(MyMatrix m)
        {
            int start_timer, elapsed_time;

            start_timer = DateTime.Now.Millisecond;
            int counter = 0;

            if (m.Y != y && m.X != x)
            {
                Console.WriteLine("Matrices not compatible. sorry");
                return(null);
            }
            MyMatrix res = new MyMatrix(x, y);

            res.Init();

            for (int _x = 0; _x < x; _x++)
            {
                for (int _y = 0; _y < y; _y++)
                {
                    res.Matrix[_x][_y] = m.Matrix[_x][_y] + matrix[_x][_y];
                    counter           += 2;
                }
                counter++;
            }
            elapsed_time = DateTime.Now.Millisecond - start_timer;
            Console.WriteLine("\nThis Operation took " + elapsed_time.ToString() + "and took " + counter.ToString() + " Steps");

            return(res);
        }
Example #3
0
        static void Main(string[] args)
        {
            choices choice = choices.def;

            string[] tokens;

            MyMatrix matr1, matr2, matr3;

            while (choice != choices.exit)
            {
                Console.WriteLine("Hey, please enter size for new matrix ");

                tokens = Console.ReadLine().Split();

                matr1 = new MyMatrix(int.Parse(tokens[0]), int.Parse(tokens[1]));
                Console.WriteLine("\nGreat. whatcha wanna do? 'a' for add, 'm' for multiplication, 'f' for fill, 'p' for print, 'i' for init, 'r' for fillrandom, 'f' to fill in from input, or 'x' to exit, and 'c' to cancel " +
                                  "working on a matrix ");
                while (choice != choices.cancel)
                {
                    choice = (choices)Console.ReadKey().KeyChar;
                    switch (choice)
                    {
                    case choices.print:
                        matr1.Print();
                        break;

                    case choices.init:
                        matr1.Init();
                        break;

                    case choices.fillrandom:
                        matr1.FillRandom();
                        break;

                    case choices.input:
                        matr1.Input();
                        break;

                    case choices.addition:
                    {
                        matr2 = new MyMatrix(matr1.X, matr1.Y);
                        matr2.Init();
                        Console.WriteLine("Great. Please enter how you wanna fill that other matrix. f for regular input, r for random");
                        if (Console.ReadKey().KeyChar == 'f')
                        {
                            matr2.Input();
                            matr3 = matr1.Add(matr2);
                            matr3.Print();
                        }
                        else if (Console.ReadKey().KeyChar == 'r')
                        {
                            matr2.FillRandom();
                            matr3 = matr1.Add(matr2);
                            matr3.Print();
                        }
                        else
                        {
                            Console.WriteLine("Well darn. that didn't work;");
                        }
                    }
                    break;

                    case choices.multiply:
                        Console.WriteLine("how large should that other one be? one num please");

                        matr2 = new MyMatrix(int.Parse(Console.ReadLine().Split()[0]), matr1.Y);
                        matr2.Init();
                        Console.WriteLine("Great. Please enter how you wanna fill that other matrix. f for regular input, r for random");
                        if (Console.ReadKey().KeyChar == 'f')
                        {
                            matr2.Input();
                            matr3 = matr1.Mult(matr2);
                            matr3.Print();
                        }
                        else if (Console.ReadKey().KeyChar == 'r')
                        {
                            matr2.FillRandom();
                            matr3 = matr1.Mult(matr2);
                            matr3.Print();
                        }
                        else
                        {
                            Console.WriteLine("Well darn. that didn't work;");
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }