Exemplo n.º 1
0
        public static VectorR Transform(VectorR v, MatrixR m)
        {
            VectorR result = new VectorR(v.GetSize());

            if (!m.IsSquared())
            {
                throw new ArgumentOutOfRangeException(
                          "Dimension", m.GetRows(), "The matrix must be squared!");
            }
            if (m.GetRows() != 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] += v[j] * m[j, i];
                }
            }
            return(result);
        }
Exemplo n.º 2
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.º 3
0
        public static double Determinant(MatrixR m)
        {
            double result = 0.0;

            if (!m.IsSquared())
            {
                throw new ArgumentOutOfRangeException(
                          "Dimension", m.GetRows(), "The matrix must be squared!");
            }
            if (m.GetRows() == 1)
            {
                result = m[0, 0];
            }
            else
            {
                for (int i = 0; i < m.GetRows(); i++)
                {
                    result += Math.Pow(-1, i) * m[0, i] * Determinant(MatrixR.Minor(m, 0, i));
                }
            }
            return(result);
        }