Beispiel #1
0
    def to_Matrix(self):
        r"""
        Convert DomainMatrix to Matrix

        Returns
        =======

        Matrix
            MutableDenseMatrix for the DomainMatrix

        Examples
        ========

        >>> from sympy import ZZ
        >>> from sympy.polys.matrices import DomainMatrix
        >>> A = DomainMatrix([
        ...    [ZZ(1), ZZ(2)],
        ...    [ZZ(3), ZZ(4)]], (2, 2), ZZ)

        >>> A.to_Matrix()
        Matrix([
            [1, 2],
            [3, 4]])

        See Also
        ========

        from_Matrix

        """
        from sympy.matrices.dense import MutableDenseMatrix
        elemlist = self.rep.to_list()
        rows_sympy = [[self.domain.to_sympy(e) for e in row] for row in elemlist]
        return MutableDenseMatrix(rows_sympy)
Beispiel #2
0
def get_coefficients(rref: MutableDenseMatrix,
                     chem_eq: str,
                     explain: bool = False) -> list:
    all_compounds = list(re.split(r"\+|=\>", chem_eq))
    coefficients = [1] * len(all_compounds)
    denoms = [num.denominator() for num in rref.col(-1)]
    the_lcm = sp.lcm(denoms)
    if explain:
        print(
            "Next, we extract the denominators of the last column from the rref:"
        )
        pause()
        print(denoms)
        pause()
        print(
            f"Then we find the least common multiple of the denominators, which is: {the_lcm}"
        )
        pause()
        print(
            "After that, we multiply each value in that last column by the LCM (and keep the absolute value), and the first coefficient is the first value, the second is the second value, etc."
        )
        pause()
        print("The coefficient of the last compound is just the LCM")
        pause()
    for i, _ in enumerate(coefficients[:-1]):
        numer, denom = rref[i, -1].p, rref[i, -1].q
        if numer == 0:
            return [0] * len(all_compounds)
        coefficients[i] = abs(numer * (the_lcm / denom))
    coefficients[-1] = the_lcm
    return coefficients
Beispiel #3
0
def get_reduced_row_echelon_form(matrix: MutableDenseMatrix,
                                 explain: bool = False) -> MutableDenseMatrix:
    rref = matrix.rref()[0]
    if explain:
        print(
            "Then we convert the matrix into \"Row Reduced Echelon Form\" (using a builtin function), which looks like:"
        )
        pause()
        print(repr(rref))
        pause()
    return rref
Beispiel #4
0
 def to_Matrix(self):
     from sympy.matrices.dense import MutableDenseMatrix
     elemlist = self.rep.to_list()
     rows_sympy = [[self.domain.to_sympy(e) for e in row]
                   for row in elemlist]
     return MutableDenseMatrix(rows_sympy)
Beispiel #5
0
 def to_Matrix(self):
     from sympy.matrices.dense import MutableDenseMatrix
     rows_sympy = [[self.domain.to_sympy(e) for e in row]
                   for row in self.rep]
     return MutableDenseMatrix(rows_sympy)
Beispiel #6
0
 def to_Matrix(self):
     rows_sympy = [[self.domain.to_sympy(e) for e in row]
                   for row in self.rows]
     return MutableDenseMatrix(rows_sympy)