Ejemplo n.º 1
0
        public static MatrixD operator *(MatrixD a, MatrixD b)
        {
            if (a.Columns != b.Rows) throw new ArgumentException("Unable to multiply matrices of different inner dimensions");

            MatrixD x = new MatrixD(a.Rows, b.Columns);

            int inner = a.Columns;
            for (int r = 0, rows = x.Rows; r < rows; r++)
            {
                for (int c = 0, cols = x.Columns; c < cols; c++)
                {
                    double d = 0.0;
                    for (int i = 0; i < inner; i++) d += a[r, i] * b[i, c];
                    x[r, c] = d;
                }
            }

            return x;
        }
Ejemplo n.º 2
0
        public static MatrixD One(int rows, int columns)
        {
            MatrixD m = new MatrixD(rows, columns);

            for (int r = 0; r < rows; r++)
            {
                for (int c = 0; c < columns; c++)
                {
                    m[r, c] = 1.0;
                }
            }

            return m;
        }
Ejemplo n.º 3
0
        public static MatrixD Identity(int dimensions)
        {
            MatrixD m = new MatrixD(dimensions, dimensions);

            for (int r = 0, rows = dimensions; r < rows; r++)
            {
                for (int c = 0, cols = dimensions; c < cols; c++)
                {
                    m[r, c] = (r == c) ? 1.0 : 0.0;
                }
            }

            return m;
        }
Ejemplo n.º 4
0
        public MatrixD Transpose()
        {
            MatrixD t = new MatrixD(Columns, Rows);

            for (int r = 0, rows = Rows; r < rows; r++)
            {
                for (int c = 0, cols = Columns; c < cols; c++)
                {
                    t[c, r] = _matrix[r, c];
                }
            }

            return t;
        }