Example #1
0
 public static void MatrixRandom(Matrixx a)
 {
     for (int i = 0; i < a.matrix.GetLength(0); i++)
     {
         for (int j = 0; j < a.matrix.GetLength(1); j++)
         {
             a.matrix[i, j] = rnd.Next(1, 10);
         }
     }
 }
Example #2
0
 public static void Print(Matrixx a)
 {
     for (int i = 0; i < a.matrix.GetLength(0); i++)
     {
         for (int j = 0; j < a.matrix.GetLength(1); j++)
         {
             Console.Write($"{a.matrix[i, j]}\t");
         }
         Console.WriteLine("\n");
     }
     Console.WriteLine("\n");
 }
Example #3
0
        public static Matrixx operator *(Matrixx a, int b)
        {
            Matrixx result = new Matrixx(a.firstSize, a.secondSize);

            Console.WriteLine("The scalar multiplication is\n");
            for (int i = 0; i < a.firstSize; i++)
            {
                for (int j = 0; j < a.secondSize; j++)
                {
                    result.matrix[i, j] = a.matrix[i, j] * b;
                }
            }
            return(result);
        }
Example #4
0
        public static Matrixx operator -(Matrixx a, Matrixx b)
        {
            Matrixx result = new Matrixx(a.firstSize, b.secondSize);

            if (a.firstSize != b.firstSize || a.secondSize != b.secondSize)
            {
                Console.WriteLine("Wrong matrix size!\n");
            }
            else
            {
                Console.WriteLine("The substraction of two matrix is \n");
                for (int i = 0; i < a.matrix.GetLength(0); i++)
                {
                    for (int j = 0; j < a.matrix.GetLength(1); j++)
                    {
                        result.matrix[i, j] = a.matrix[i, j] - b.matrix[i, j];
                    }
                }
            }
            return(result);
        }
Example #5
0
        static void Main(string[] args)
        {
            Matrixx firtsMatrix = new Matrixx(3, 3);

            Matrixx.MatrixRandom(firtsMatrix);
            Console.WriteLine("The first matrix is\n");
            Matrixx.Print(firtsMatrix);

            Matrixx secondMatrix = new Matrixx(3, 3);

            Matrixx.MatrixRandom(secondMatrix);
            Console.WriteLine("The second matrix is\n");
            Matrixx.Print(secondMatrix);

            Matrixx.Print(firtsMatrix + secondMatrix);
            Matrixx.Print(firtsMatrix - secondMatrix);
            Matrixx.Print(firtsMatrix * secondMatrix);
            Matrixx.Print(firtsMatrix * 5);

            Console.ReadLine();
        }
Example #6
0
        public static Matrixx operator *(Matrixx a, Matrixx b)
        {
            Matrixx result = new Matrixx(a.firstSize, b.secondSize);

            if (a.secondSize != b.firstSize)
            {
                Console.WriteLine("Wrong matrix size!\n");
            }
            else
            {
                Console.WriteLine("The multiplication of two matrix is\n");
                for (int i = 0; i < a.firstSize; i++)
                {
                    for (int j = 0; j < b.secondSize; j++)
                    {
                        for (int k = 0; k < a.secondSize; k++)
                        {
                            result.matrix[i, j] += a.matrix[i, k] * b.matrix[k, j];
                        }
                    }
                }
            }
            return(result);
        }