Esempio n. 1
0
        public static MyMatrix Transpose(MyMatrix a)
        {
            int      rows   = a.RowCount;
            int      cols   = a.ColCount;
            MyMatrix result = new MyMatrix(cols, rows);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    result[j, i] = a[i, j];
                }
            }
            return(result);
        }
Esempio n. 2
0
        public static MyMatrix Negate(MyMatrix a)
        {
            int      rows   = a.RowCount;
            int      cols   = a.ColCount;
            MyMatrix result = new MyMatrix(rows, cols);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    result[i, j] = -a[i, j];
                }
            }
            return(result);
        }
Esempio n. 3
0
        public static MyMatrix Substract(MyMatrix a, MyMatrix b)
        {
            if (a.RowCount != b.RowCount || a.ColCount != b.ColCount)
            {
                throw new InvalidOperationException();
            }
            int      rows   = a.RowCount;
            int      cols   = a.ColCount;
            MyMatrix result = new MyMatrix(rows, cols);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    result[i, j] = a[i, j] - b[i, j];
                }
            }
            return(result);
        }
Esempio n. 4
0
        public static MyMatrix Multiply(MyMatrix a, double[] b)
        {
            if (a.ColCount != b.Length)
            {
                throw new InvalidOperationException();
            }

            int      rows   = a.RowCount;
            MyMatrix result = new MyMatrix(rows, 1);

            for (int i = 0; i < rows; i++)
            {
                double temp = 0;
                for (int j = 0; j < b.Length; j++)
                {
                    temp += a[i, j] * b[j];
                }
                result[i, 0] = temp;
            }
            return(result);
        }
Esempio n. 5
0
        public void Transpose()
        {
            MyMatrix tranpose = Transpose(this);

            this.elements = tranpose.elements;
        }