Matrix

Matrix

Matrix()

A matrix with rational polynomial coefficients.

Methods

Name Description
__add__ Add two matrices self and rhs, returning the result.
__copy__ Copy the matrix.
__eq__ Compare two matrices.
__getitem__ Get the entry at position key in the matrix.
__matmul__ Matrix multiply self and rhs, returning the result.
__mul__ Matrix multiply self and rhs, returning the result.
__neg__ Negate the matrix, returning the result.
__neq__ Compare two matrices.
__new__ Create a new zeroed matrix with nrows rows and ncols columns.
__rmatmul__ Matrix multiply rhs and self, returning the result.
__rmul__ Matrix multiply rhs and self, returning the result.
__str__ Print the matrix in a human-readable format.
__sub__ Subtract matrix rhs from self, returning the result.
__truediv__ Divide this matrix by scalar rhs and return the result.
augment Augment the matrix with another matrix, e.g
content Get the content, i.e., the GCD of the coefficients.
det Return the determinant of the matrix.
eye Create a new matrix with the scalars diag on the main diagonal and zeroes elsewhere.
format Convert the matrix into a human-readable string, with tunable settings.
from_linear Create a new matrix from a 1-dimensional vector of scalars.
from_nested Create a new matrix from a 2-dimensional vector of scalars.
identity Create a new square matrix with nrows rows and ones on the main diagonal and zeroes elsewhere.
inv Return the inverse of the matrix, if it exists.
is_diagonal Return true iff every non- main diagonal entry in the matrix is zero.
is_zero Return true iff every entry in the matrix is zero.
map Apply a function f to every entry of the matrix.
ncols Get the number of columns in the matrix.
nrows Get the number of rows in the matrix.
primitive_part Construct the same matrix, but with the content removed.
row_reduce Row-reduce the first max_col columns of the matrix in-place using Gaussian elimination and return the rank.
solve Solve A * x = b for x, where A is the current matrix.
solve_any Solve A * x = b for x, where A is the current matrix and return any solution if the system is underdetermined.
split_col Split the matrix into two matrices at column col.
swap_cols Swap columns i and j of the matrix in-place.
swap_rows Swap rows i and j of the matrix in-place, starting from column start.
to_latex Convert the matrix into a LaTeX string.
transpose Return the transpose of the matrix.
vec Create a new column vector from a list of scalars.

__add__

Matrix.__add__(rhs: Matrix) -> Matrix

Add two matrices self and rhs, returning the result.

__copy__

Matrix.__copy__() -> Matrix

Copy the matrix.

__eq__

Matrix.__eq__(other: Matrix) -> bool

Compare two matrices.

__getitem__

Matrix.__getitem__(key: Tuple[int, int]) -> RationalPolynomial

Get the entry at position key in the matrix.

__matmul__

Matrix.__matmul__(rhs: Matrix | RationalPolynomial | Polynomial | Expression | int) -> Matrix

Matrix multiply self and rhs, returning the result.

__mul__

Matrix.__mul__(rhs: Matrix | RationalPolynomial | Polynomial | Expression | int) -> Matrix

Matrix multiply self and rhs, returning the result.

__neg__

Matrix.__neg__() -> Matrix

Negate the matrix, returning the result.

__neq__

Matrix.__neq__(other: Matrix) -> bool

Compare two matrices.

__new__

Matrix.__new__(nrows: int, ncols: int) -> Matrix

Create a new zeroed matrix with nrows rows and ncols columns.

__rmatmul__

Matrix.__rmatmul__(rhs: RationalPolynomial | Polynomial | Expression | int) -> Matrix

Matrix multiply rhs and self, returning the result.

__rmul__

Matrix.__rmul__(rhs: RationalPolynomial | Polynomial | Expression | int) -> Matrix

Matrix multiply rhs and self, returning the result.

__str__

Matrix.__str__() -> str

Print the matrix in a human-readable format.

__sub__

Matrix.__sub__(rhs: Matrix) -> Matrix

Subtract matrix rhs from self, returning the result.

__truediv__

Matrix.__truediv__(rhs: RationalPolynomial | Polynomial | Expression | int) -> Matrix

Divide this matrix by scalar rhs and return the result.

augment

Matrix.augment(b: Matrix) -> Matrix

Augment the matrix with another matrix, e.g. create [A B] from matrix A and B.

Returns an error when the matrices do not have the same number of rows.

content

Matrix.content() -> RationalPolynomial

Get the content, i.e., the GCD of the coefficients.

det

Matrix.det() -> RationalPolynomial

Return the determinant of the matrix.

eye

Matrix.eye(diag: Sequence[RationalPolynomial | Polynomial | Expression | int]) -> Matrix

Create a new matrix with the scalars diag on the main diagonal and zeroes elsewhere.

format

Matrix.format(
    mode: PrintMode = PrintMode.Symbolica,
    max_line_length: int | None = 80,
    indentation: int = 4,
    fill_indented_lines: bool = True,
    pretty_matrix = True,
    number_thousands_separator: Optional[str] = None,
    multiplication_operator: str = '*',
    double_star_for_exponentiation: bool = False,
    square_brackets_for_function: bool = False,
    function_brackets: tuple[str, str] = ('(', ')'),
    num_exp_as_superscript: bool = True,
    precision: Optional[int] = None,
    show_namespaces: bool = False,
    hide_namespace: Optional[str] = None,
    include_attributes: bool = False,
    max_terms: Optional[int] = None,
    custom_print_mode: Optional[int] = None,
) -> str

Convert the matrix into a human-readable string, with tunable settings.

from_linear

Matrix.from_linear(
    nrows: int,
    ncols: int,
    entries: Sequence[RationalPolynomial | Polynomial | Expression | int],
) -> Matrix

Create a new matrix from a 1-dimensional vector of scalars.

from_nested

Matrix.from_nested(entries: Sequence[Sequence[RationalPolynomial | Polynomial | Expression | int]]) -> Matrix

Create a new matrix from a 2-dimensional vector of scalars.

identity

Matrix.identity(nrows: int) -> Matrix

Create a new square matrix with nrows rows and ones on the main diagonal and zeroes elsewhere.

inv

Matrix.inv() -> Matrix

Return the inverse of the matrix, if it exists.

is_diagonal

Matrix.is_diagonal() -> bool

Return true iff every non- main diagonal entry in the matrix is zero.

is_zero

Matrix.is_zero() -> bool

Return true iff every entry in the matrix is zero.

map

Matrix.map(f: Callable[[RationalPolynomial], RationalPolynomial]) -> Matrix

Apply a function f to every entry of the matrix.

ncols

Matrix.ncols() -> int

Get the number of columns in the matrix.

nrows

Matrix.nrows() -> int

Get the number of rows in the matrix.

primitive_part

Matrix.primitive_part() -> Matrix

Construct the same matrix, but with the content removed.

row_reduce

Matrix.row_reduce(max_col: int) -> int

Row-reduce the first max_col columns of the matrix in-place using Gaussian elimination and return the rank.

solve

Matrix.solve(b: Matrix) -> Matrix

Solve A * x = b for x, where A is the current matrix.

solve_any

Matrix.solve_any(b: Matrix) -> Matrix

Solve A * x = b for x, where A is the current matrix and return any solution if the system is underdetermined.

split_col

Matrix.split_col(col: int) -> Tuple[Matrix, Matrix]

Split the matrix into two matrices at column col.

swap_cols

Matrix.swap_cols(i: int, j: int) -> None

Swap columns i and j of the matrix in-place.

swap_rows

Matrix.swap_rows(i: int, j: int, start: int = 0) -> None

Swap rows i and j of the matrix in-place, starting from column start.

to_latex

Matrix.to_latex() -> str

Convert the matrix into a LaTeX string.

transpose

Matrix.transpose() -> Matrix

Return the transpose of the matrix.

vec

Matrix.vec(entries: Sequence[RationalPolynomial | Polynomial | Expression | int]) -> Matrix

Create a new column vector from a list of scalars.