Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 5
0
        public void Transpose()
        {
            MyMatrix tranpose = Transpose(this);

            this.elements = tranpose.elements;
        }