Exemplo n.º 1
0
        public static MatrixR Minor(MatrixR m, int row, int col)
        {
            MatrixR mm = new MatrixR(m.GetRows() - 1, m.GetCols() - 1);
            int     ii = 0, jj = 0;

            for (int i = 0; i < m.GetRows(); i++)
            {
                if (i == row)
                {
                    continue;
                }
                jj = 0;
                for (int j = 0; j < m.GetCols(); j++)
                {
                    if (j == col)
                    {
                        continue;
                    }
                    mm[ii, jj] = m[i, j];
                    jj++;
                }
                ii++;
            }
            return(mm);
        }
Exemplo n.º 2
0
        public static VectorR Transform(MatrixR m, VectorR v)
        {
            VectorR result = new VectorR(v.GetSize());

            if (!m.IsSquared())
            {
                throw new ArgumentOutOfRangeException(
                          "Dimension", m.GetRows(), "The matrix must be squared!");
            }
            if (m.GetCols() != v.GetSize())
            {
                throw new ArgumentOutOfRangeException(
                          "Size", v.GetSize(), "The size of the vector must be equal"
                          + "to the number of rows of the matrix!");
            }
            for (int i = 0; i < m.GetRows(); i++)
            {
                result[i] = 0.0;
                for (int j = 0; j < m.GetCols(); j++)
                {
                    result[i] += m[i, j] * v[j];
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        public static MatrixR Adjoint(MatrixR m)
        {
            if (!m.IsSquared())
            {
                throw new ArgumentOutOfRangeException(
                          "Dimension", m.GetRows(), "The matrix must be squared!");
            }
            MatrixR ma = new MatrixR(m.GetRows(), m.GetCols());

            for (int i = 0; i < m.GetRows(); i++)
            {
                for (int j = 0; j < m.GetCols(); j++)
                {
                    ma[i, j] = Math.Pow(-1, i + j) * (Determinant(Minor(m, i, j)));
                }
            }
            return(ma.GetTranspose());
        }
Exemplo n.º 4
0
 public static bool CompareDimension(MatrixR m1, MatrixR m2)
 {
     if (m1.GetRows() == m2.GetRows() && m1.GetCols() == m2.GetCols())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 5
0
 public MatrixR(MatrixR m)
 {
     Rows   = m.GetRows();
     Cols   = m.GetCols();
     matrix = m.matrix;
 }