Esempio n. 1
0
        public static RMatrix Adjoint(RMatrix mat)
        {
            if (!mat.IsSquared())
            {
                throw new Exception("The matrix must be squared!");
            }
            RMatrix ma = new RMatrix(mat.GetnRows, mat.GetnCols);

            for (int i = 0; i < mat.GetnRows; i++)
            {
                for (int j = 0; j < mat.GetnCols; j++)
                {
                    ma[i, j] = Math.Pow(-1, i + j) * (Determinant(Minor(mat, i, j)));
                }
            }
            return(ma.GetTranspose());
        }
Esempio n. 2
0
        public static double Determinant(RMatrix mat)
        {
            double result = 0.0;

            if (!mat.IsSquared())
            {
                throw new Exception("The matrix must be squared!");
            }
            if (mat.GetnRows == 1)
            {
                result = mat[0, 0];
            }
            else
            {
                for (int i = 0; i < mat.GetnRows; i++)
                {
                    result += Math.Pow(-1, i) * mat[0, i] *
                              Determinant(RMatrix.Minor(mat, 0, i));
                }
            }
            return(result);
        }
Esempio n. 3
0
        public static RVector Transform(RVector vec, RMatrix mat)
        {
            RVector result = new RVector(vec.GetVectorSize);

            if (!mat.IsSquared())
            {
                throw new Exception("The matrix must be squared!");
            }
            if (mat.GetnRows != vec.GetVectorSize)
            {
                throw new Exception("The ndim of the vector must be equal"
                                    + " to the number of rows of the matrix!");
            }
            for (int i = 0; i < mat.GetnRows; i++)
            {
                result[i] = 0.0;
                for (int j = 0; j < mat.GetnCols; j++)
                {
                    result[i] += vec[j] * mat[j, i];
                }
            }
            return(result);
        }