public static MyMatrix multiply(MyMatrix a, MyMatrix b)
        {
            double[,] array1 = new double[a.GetHeight(), b.GetWidth()];
            for (int i = 0; i < a.GetWidth(); i++)
            {
                for (int j = 0; j < b.GetWidth(); j++)
                {
                    for (int k = 0; k < b.GetWidth(); k++)
                    {
                        array1[i, j] += a[i, k] * b[k, j];
                    }
                }
            }
            MyMatrix resMass = new MyMatrix(array1);

            return(resMass);
        }
        public static MyMatrix Sum(MyMatrix first, MyMatrix second)
        {
            double[,] array1 = new double[first.GetHeight(), first.GetWidth()];
            if (first.GetHeight() != second.GetHeight() || first.GetWidth() != second.GetWidth())
            {
                Console.WriteLine("Матрицы не одинаковые. Невозможно применить сложение");
            }
            else
            {
                for (int i = 0; i < first.GetHeight(); i++)
                {
                    for (int j = 0; j < first.GetWidth(); j++)
                    {
                        array1[i, j] = first[i, j] + second[i, j];
                    }
                }
            }
            MyMatrix resMass = new MyMatrix(array1);

            return(resMass);
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Первая матрица с масивов строк");
            string[] temp = { "1 3 4", "5 7 8", "9 10 12" };
            MyMatrix mat  = new MyMatrix(temp);

            Console.WriteLine(mat);

            Console.WriteLine("Вторая матрица с одной строчки");
            string   temp2 = "10 12 15/15 8 5/17 22 9";
            MyMatrix mat2  = new MyMatrix(temp2);

            Console.WriteLine(mat2);

            Console.WriteLine("Сумма первых двух матриц");
            Console.WriteLine(mat + mat2);

            Console.WriteLine("Произведение первых двух матриц");
            Console.WriteLine(mat * mat2);

            Console.WriteLine("Транспонированная вторая матрица");
            Console.WriteLine(mat2.GetTransponedCopy());
            Console.ReadKey();
        }
 public MyMatrix(MyMatrix mat)
 {
     MyMatrix _matrix = mat;
 }
        public MyMatrix GetTransponedCopy()
        {
            MyMatrix res = new MyMatrix(GetTransponedArray());

            return(res);
        }
 public static MyMatrix operator *(MyMatrix a, MyMatrix b)
 {
     return(MyMatrix.multiply(a, b));
 }
 public static MyMatrix operator +(MyMatrix first, MyMatrix second)
 {
     return(MyMatrix.Sum(first, second));
 }