GiNaC  1.8.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GiNaC::matrix Class Reference

Symbolic matrices. More...

#include <matrix.h>

Inheritance diagram for GiNaC::matrix:
GiNaC::basic GiNaC::refcounted

Public Member Functions

 matrix (unsigned r, unsigned c)
 Very common ctor. More...
 
 matrix (unsigned r, unsigned c, const lst &l)
 Construct matrix from (flat) list of elements. More...
 
 matrix (std::initializer_list< std::initializer_list< ex >> l)
 Construct a matrix from an 2 dimensional initializer list. More...
 
size_t nops () const override
 nops is defined to be rows x columns. More...
 
ex op (size_t i) const override
 returns matrix entry at position (i/col, icol). More...
 
exlet_op (size_t i) override
 returns writable matrix entry at position (i/col, icol). More...
 
ex evalm () const override
 Evaluate sums, products and integer powers of matrices. More...
 
ex subs (const exmap &m, unsigned options=0) const override
 Substitute a set of objects by arbitrary expressions. More...
 
ex eval_indexed (const basic &i) const override
 Automatic symbolic evaluation of an indexed matrix. More...
 
ex add_indexed (const ex &self, const ex &other) const override
 Sum of two indexed matrices. More...
 
ex scalar_mul_indexed (const ex &self, const numeric &other) const override
 Product of an indexed matrix with a number. More...
 
bool contract_with (exvector::iterator self, exvector::iterator other, exvector &v) const override
 Contraction of an indexed matrix with something else. More...
 
ex conjugate () const override
 Complex conjugate every matrix entry. More...
 
ex real_part () const override
 
ex imag_part () const override
 
void archive (archive_node &n) const override
 Save (a.k.a. More...
 
void read_archive (const archive_node &n, lst &syms) override
 Read (a.k.a. More...
 
unsigned rows () const
 Get number of rows. More...
 
unsigned cols () const
 Get number of columns. More...
 
matrix add (const matrix &other) const
 Sum of matrices. More...
 
matrix sub (const matrix &other) const
 Difference of matrices. More...
 
matrix mul (const matrix &other) const
 Product of matrices. More...
 
matrix mul (const numeric &other) const
 Product of matrix and scalar. More...
 
matrix mul_scalar (const ex &other) const
 Product of matrix and scalar expression. More...
 
matrix pow (const ex &expn) const
 Power of a matrix. More...
 
const exoperator() (unsigned ro, unsigned co) const
 operator() to access elements for reading. More...
 
exoperator() (unsigned ro, unsigned co)
 operator() to access elements for writing. More...
 
matrixset (unsigned ro, unsigned co, const ex &value)
 
matrix transpose () const
 Transposed of an m x n matrix, producing a new n x m matrix object that represents the transposed. More...
 
ex determinant (unsigned algo=determinant_algo::automatic) const
 Determinant of square matrix. More...
 
ex trace () const
 Trace of a matrix. More...
 
ex charpoly (const ex &lambda) const
 Characteristic Polynomial. More...
 
matrix inverse () const
 Inverse of this matrix, with automatic algorithm selection. More...
 
matrix inverse (unsigned algo) const
 Inverse of this matrix. More...
 
matrix solve (const matrix &vars, const matrix &rhs, unsigned algo=solve_algo::automatic) const
 Solve a linear system consisting of a m x n matrix and a m x p right hand side by applying an elimination scheme to the augmented matrix. More...
 
unsigned rank () const
 Compute the rank of this matrix. More...
 
unsigned rank (unsigned solve_algo) const
 Compute the rank of this matrix using the given algorithm, which should be a member of enum solve_algo. More...
 
bool is_zero_matrix () const
 Function to check that all elements of the matrix are zero. More...
 
- Public Member Functions inherited from GiNaC::basic
virtual ~basic ()
 basic destructor, virtual because class ex will delete objects of derived classes via a basic*. More...
 
 basic (const basic &other)
 
const basicoperator= (const basic &other)
 basic assignment operator: the other object might be of a derived class. More...
 
virtual basicduplicate () const
 Create a clone of this object on the heap. More...
 
virtual ex eval () const
 Perform automatic non-interruptive term rewriting rules. More...
 
virtual ex evalf () const
 Evaluate object numerically. More...
 
virtual ex eval_integ () const
 Evaluate integrals, if result is known. More...
 
virtual void print (const print_context &c, unsigned level=0) const
 Output to stream. More...
 
virtual void dbgprint () const
 Little wrapper around print to be called within a debugger. More...
 
virtual void dbgprinttree () const
 Little wrapper around printtree to be called within a debugger. More...
 
virtual unsigned precedence () const
 Return relative operator precedence (for parenthezing output). More...
 
virtual bool info (unsigned inf) const
 Information about the object. More...
 
virtual ex operator[] (const ex &index) const
 
virtual ex operator[] (size_t i) const
 
virtual exoperator[] (const ex &index)
 
virtual exoperator[] (size_t i)
 
virtual bool has (const ex &other, unsigned options=0) const
 Test for occurrence of a pattern. More...
 
virtual bool match (const ex &pattern, exmap &repls) const
 Check whether the expression matches a given pattern. More...
 
virtual ex map (map_function &f) const
 Construct new expression by applying the specified function to all sub-expressions (one level only, not recursively). More...
 
virtual void accept (GiNaC::visitor &v) const
 
virtual bool is_polynomial (const ex &var) const
 Check whether this is a polynomial in the given variables. More...
 
virtual int degree (const ex &s) const
 Return degree of highest power in object s. More...
 
virtual int ldegree (const ex &s) const
 Return degree of lowest power in object s. More...
 
virtual ex coeff (const ex &s, int n=1) const
 Return coefficient of degree n in object s. More...
 
virtual ex expand (unsigned options=0) const
 Expand expression, i.e. More...
 
virtual ex collect (const ex &s, bool distributed=false) const
 Sort expanded expression in terms of powers of some object(s). More...
 
virtual ex series (const relational &r, int order, unsigned options=0) const
 Default implementation of ex::series(). More...
 
virtual ex normal (exmap &repl, exmap &rev_lookup, lst &modifier) const
 Default implementation of ex::normal(). More...
 
virtual ex to_rational (exmap &repl) const
 Default implementation of ex::to_rational(). More...
 
virtual ex to_polynomial (exmap &repl) const
 
virtual numeric integer_content () const
 
virtual ex smod (const numeric &xi) const
 Apply symmetric modular homomorphism to an expanded multivariate polynomial. More...
 
virtual numeric max_coefficient () const
 Implementation ex::max_coefficient(). More...
 
virtual exvector get_free_indices () const
 Return a vector containing the free indices of an expression. More...
 
virtual return_type_t return_type_tinfo () const
 
template<class T >
void print_dispatch (const print_context &c, unsigned level) const
 Like print(), but dispatch to the specified class. More...
 
void print_dispatch (const registered_class_info &ri, const print_context &c, unsigned level) const
 Like print(), but dispatch to the specified class. More...
 
ex subs_one_level (const exmap &m, unsigned options) const
 Helper function for subs(). More...
 
ex diff (const symbol &s, unsigned nth=1) const
 Default interface of nth derivative ex::diff(s, n). More...
 
int compare (const basic &other) const
 Compare objects syntactically to establish canonical ordering. More...
 
bool is_equal (const basic &other) const
 Test for syntactic equality. More...
 
const basichold () const
 Stop further evaluation. More...
 
unsigned gethash () const
 
const basicsetflag (unsigned f) const
 Set some status_flags. More...
 
const basicclearflag (unsigned f) const
 Clear some status_flags. More...
 
- Public Member Functions inherited from GiNaC::refcounted
 refcounted () noexcept
 
unsigned int add_reference () noexcept
 
unsigned int remove_reference () noexcept
 
unsigned int get_refcount () const noexcept
 
void set_refcount (unsigned int r) noexcept
 

Protected Member Functions

 matrix (unsigned r, unsigned c, const exvector &m2)
 Ctor from representation, for internal use only. More...
 
 matrix (unsigned r, unsigned c, exvector &&m2)
 
bool match_same_type (const basic &other) const override
 Returns true if the attributes of two objects are similar enough for a match. More...
 
unsigned return_type () const override
 
ex determinant_minor () const
 Recursive determinant for small matrices having at least one symbolic entry. More...
 
std::vector< unsigned > echelon_form (unsigned algo, int n)
 
int gauss_elimination (const bool det=false)
 Perform the steps of an ordinary Gaussian elimination to bring the m x n matrix into an upper echelon form. More...
 
int division_free_elimination (const bool det=false)
 Perform the steps of division free elimination to bring the m x n matrix into an upper echelon form. More...
 
int fraction_free_elimination (const bool det=false)
 Perform the steps of Bareiss' one-step fraction free elimination to bring the matrix into an upper echelon form. More...
 
std::vector< unsigned > markowitz_elimination (unsigned n)
 
int pivot (unsigned ro, unsigned co, bool symbolic=true)
 Partial pivoting method for matrix elimination schemes. More...
 
void print_elements (const print_context &c, const char *row_start, const char *row_end, const char *row_sep, const char *col_sep) const
 
void do_print (const print_context &c, unsigned level) const
 
void do_print_latex (const print_latex &c, unsigned level) const
 
void do_print_python_repr (const print_python_repr &c, unsigned level) const
 
- Protected Member Functions inherited from GiNaC::basic
 basic ()
 
virtual ex eval_ncmul (const exvector &v) const
 
virtual ex derivative (const symbol &s) const
 Default implementation of ex::diff(). More...
 
virtual int compare_same_type (const basic &other) const
 Returns order relation between two objects of same type. More...
 
virtual bool is_equal_same_type (const basic &other) const
 Returns true if two objects of same type are equal. More...
 
virtual unsigned calchash () const
 Compute the hash value of an object and if it makes sense to store it in the objects status_flags, do so. More...
 
void ensure_if_modifiable () const
 Ensure the object may be modified without hurting others, throws if this is not the case. More...
 
void do_print (const print_context &c, unsigned level) const
 Default output to stream. More...
 
void do_print_tree (const print_tree &c, unsigned level) const
 Tree output to stream. More...
 
void do_print_python_repr (const print_python_repr &c, unsigned level) const
 Python parsable output to stream. More...
 

Protected Attributes

unsigned row
 number of rows More...
 
unsigned col
 number of columns More...
 
exvector m
 representation (cols indexed first) More...
 
- Protected Attributes inherited from GiNaC::basic
unsigned flags
 of type status_flags More...
 
unsigned hashvalue
 hash value More...
 

Detailed Description

Symbolic matrices.

Definition at line 37 of file matrix.h.

Constructor & Destructor Documentation

◆ matrix() [1/5]

GiNaC::matrix::matrix ( unsigned  r,
unsigned  c 
)

Very common ctor.

Initializes to r x c-dimensional zero-matrix.

Parameters
rnumber of rows
cnumber of cols

Definition at line 71 of file matrix.cpp.

References GiNaC::status_flags::not_shareable, and GiNaC::basic::setflag().

Referenced by add(), conjugate(), determinant(), imag_part(), mul(), mul_scalar(), real_part(), sub(), subs(), and transpose().

◆ matrix() [2/5]

GiNaC::matrix::matrix ( unsigned  r,
unsigned  c,
const lst l 
)

Construct matrix from (flat) list of elements.

If the list has fewer elements than the matrix, the remaining matrix elements are set to zero. If the list has more elements than the matrix, the excessive elements are thrown away.

Definition at line 80 of file matrix.cpp.

References c, m, GiNaC::status_flags::not_shareable, r, GiNaC::basic::setflag(), and x.

◆ matrix() [3/5]

GiNaC::matrix::matrix ( std::initializer_list< std::initializer_list< ex >>  l)

Construct a matrix from an 2 dimensional initializer list.

Throws an exception if some row has a different length than all the others.

Definition at line 99 of file matrix.cpp.

References c, col, m, GiNaC::status_flags::not_shareable, r, row, and GiNaC::basic::setflag().

◆ matrix() [4/5]

GiNaC::matrix::matrix ( unsigned  r,
unsigned  c,
const exvector m2 
)
protected

Ctor from representation, for internal use only.

Definition at line 119 of file matrix.cpp.

References GiNaC::status_flags::not_shareable, and GiNaC::basic::setflag().

◆ matrix() [5/5]

GiNaC::matrix::matrix ( unsigned  r,
unsigned  c,
exvector &&  m2 
)
protected

Definition at line 124 of file matrix.cpp.

References GiNaC::status_flags::not_shareable, and GiNaC::basic::setflag().

Member Function Documentation

◆ nops()

size_t GiNaC::matrix::nops ( ) const
overridevirtual

nops is defined to be rows x columns.

Reimplemented from GiNaC::basic.

Definition at line 206 of file matrix.cpp.

References col, and row.

Referenced by add_indexed(), let_op(), op(), and scalar_mul_indexed().

◆ op()

ex GiNaC::matrix::op ( size_t  i) const
overridevirtual

returns matrix entry at position (i/col, icol).

Reimplemented from GiNaC::basic.

Definition at line 212 of file matrix.cpp.

References GINAC_ASSERT, m, and nops().

Referenced by add_indexed(), contract_with(), and scalar_mul_indexed().

◆ let_op()

ex & GiNaC::matrix::let_op ( size_t  i)
overridevirtual

returns writable matrix entry at position (i/col, icol).

Reimplemented from GiNaC::basic.

Definition at line 220 of file matrix.cpp.

References GiNaC::basic::ensure_if_modifiable(), GINAC_ASSERT, m, and nops().

◆ evalm()

ex GiNaC::matrix::evalm ( ) const
inlineoverridevirtual

Evaluate sums, products and integer powers of matrices.

Reimplemented from GiNaC::basic.

Definition at line 55 of file matrix.h.

◆ subs()

ex GiNaC::matrix::subs ( const exmap m,
unsigned  options = 0 
) const
overridevirtual

Substitute a set of objects by arbitrary expressions.

The ex returned will already be evaluated.

Reimplemented from GiNaC::basic.

Definition at line 228 of file matrix.cpp.

References c, col, m, matrix(), options, r, and row.

Referenced by fraction_free_elimination().

◆ eval_indexed()

ex GiNaC::matrix::eval_indexed ( const basic i) const
overridevirtual

◆ add_indexed()

ex GiNaC::matrix::add_indexed ( const ex self,
const ex other 
) const
overridevirtual

Sum of two indexed matrices.

Reimplemented from GiNaC::basic.

Definition at line 397 of file matrix.cpp.

References add(), col, GINAC_ASSERT, GiNaC::basic::is_equal(), GiNaC::ex::nops(), nops(), GiNaC::ex::op(), op(), row, and transpose().

◆ scalar_mul_indexed()

ex GiNaC::matrix::scalar_mul_indexed ( const ex self,
const numeric other 
) const
overridevirtual

Product of an indexed matrix with a number.

Reimplemented from GiNaC::basic.

Definition at line 433 of file matrix.cpp.

References GINAC_ASSERT, mul(), nops(), GiNaC::ex::op(), and op().

◆ contract_with()

bool GiNaC::matrix::contract_with ( exvector::iterator  self,
exvector::iterator  other,
exvector v 
) const
overridevirtual

Contraction of an indexed matrix with something else.

Reimplemented from GiNaC::basic.

Definition at line 448 of file matrix.cpp.

References GiNaC::_ex1, col, GINAC_ASSERT, GiNaC::is_dummy_pair(), mul(), GiNaC::ex::op(), op(), row, and transpose().

◆ conjugate()

ex GiNaC::matrix::conjugate ( ) const
overridevirtual

Complex conjugate every matrix entry.

Reimplemented from GiNaC::basic.

Definition at line 239 of file matrix.cpp.

References GiNaC::are_ex_trivially_equal(), col, m, matrix(), row, and x.

◆ real_part()

ex GiNaC::matrix::real_part ( ) const
overridevirtual

Reimplemented from GiNaC::basic.

Definition at line 264 of file matrix.cpp.

References col, m, matrix(), and row.

◆ imag_part()

ex GiNaC::matrix::imag_part ( ) const
overridevirtual

Reimplemented from GiNaC::basic.

Definition at line 273 of file matrix.cpp.

References col, m, matrix(), and row.

◆ archive()

void GiNaC::matrix::archive ( archive_node n) const
overridevirtual

Save (a.k.a.

serialize) object into archive.

Reimplemented from GiNaC::basic.

Definition at line 152 of file matrix.cpp.

References col, m, n, and row.

◆ read_archive()

void GiNaC::matrix::read_archive ( const archive_node n,
lst syms 
)
overridevirtual

Read (a.k.a.

deserialize) object from archive.

Reimplemented from GiNaC::basic.

Definition at line 134 of file matrix.cpp.

References col, m, n, and row.

◆ match_same_type()

bool GiNaC::matrix::match_same_type ( const basic other) const
overrideprotectedvirtual

Returns true if the attributes of two objects are similar enough for a match.

This function must not match subexpressions (this is already done by basic::match()). Only attributes not accessible by op() should be compared. This is also the reason why this function doesn't take the wildcard replacement list from match() as an argument: only subexpressions are subject to wildcard matches. Also, this function only needs to be implemented for container classes because is_equal_same_type() is automatically used instead of match_same_type() if nops() == 0.

See also
basic::match

Reimplemented from GiNaC::basic.

Definition at line 309 of file matrix.cpp.

References col, cols(), GINAC_ASSERT, row, and rows().

◆ return_type()

unsigned GiNaC::matrix::return_type ( ) const
inlineoverrideprotectedvirtual

Reimplemented from GiNaC::basic.

Definition at line 71 of file matrix.h.

References GiNaC::return_types::noncommutative.

◆ rows()

unsigned GiNaC::matrix::rows ( ) const
inline

Get number of rows.

Definition at line 75 of file matrix.h.

References row.

Referenced by division_free_elimination(), fraction_free_elimination(), gauss_elimination(), GiNaC::lsolve(), match_same_type(), mul(), solve(), and transpose().

◆ cols()

unsigned GiNaC::matrix::cols ( ) const
inline

◆ add()

matrix GiNaC::matrix::add ( const matrix other) const

Sum of matrices.

Exceptions
logic_error(incompatible matrices)

Definition at line 555 of file matrix.cpp.

References col, m, matrix(), and row.

Referenced by add_indexed(), and GiNaC::add::evalm().

◆ sub()

matrix GiNaC::matrix::sub ( const matrix other) const

Difference of matrices.

Exceptions
logic_error(incompatible matrices)

Definition at line 572 of file matrix.cpp.

References col, m, matrix(), and row.

◆ mul() [1/2]

matrix GiNaC::matrix::mul ( const matrix other) const

Product of matrices.

Exceptions
logic_error(incompatible matrices)

Definition at line 589 of file matrix.cpp.

References c, col, cols(), GiNaC::is_zero(), m, matrix(), row, and rows().

Referenced by charpoly(), contract_with(), GiNaC::ncmul::evalm(), pow(), and scalar_mul_indexed().

◆ mul() [2/2]

matrix GiNaC::matrix::mul ( const numeric other) const

Product of matrix and scalar.

Definition at line 610 of file matrix.cpp.

References c, col, m, matrix(), r, and row.

◆ mul_scalar()

matrix GiNaC::matrix::mul_scalar ( const ex other) const

Product of matrix and scalar expression.

Definition at line 623 of file matrix.cpp.

References c, col, GiNaC::return_types::commutative, m, matrix(), r, GiNaC::ex::return_type(), and row.

◆ pow()

matrix GiNaC::matrix::pow ( const ex expn) const

Power of a matrix.

Currently handles integer exponents only.

Definition at line 639 of file matrix.cpp.

References GiNaC::_ex1, GiNaC::_num1_p, GiNaC::_num2_p, col, GiNaC::ex::info(), GiNaC::info_flags::integer, inverse(), GiNaC::numeric::is_odd(), GiNaC::numeric::is_zero(), mul(), GiNaC::info_flags::negative, r, and row.

◆ operator()() [1/2]

const ex & GiNaC::matrix::operator() ( unsigned  ro,
unsigned  co 
) const

operator() to access elements for reading.

Parameters
rorow of element
cocolumn of element
Exceptions
range_error(index out of range)

Definition at line 686 of file matrix.cpp.

References col, m, and row.

◆ operator()() [2/2]

ex & GiNaC::matrix::operator() ( unsigned  ro,
unsigned  co 
)

operator() to access elements for writing.

Parameters
rorow of element
cocolumn of element
Exceptions
range_error(index out of range)

Definition at line 700 of file matrix.cpp.

References col, GiNaC::basic::ensure_if_modifiable(), m, and row.

◆ set()

matrix& GiNaC::matrix::set ( unsigned  ro,
unsigned  co,
const ex value 
)
inline

Definition at line 87 of file matrix.h.

References value.

◆ transpose()

matrix GiNaC::matrix::transpose ( ) const

Transposed of an m x n matrix, producing a new n x m matrix object that represents the transposed.

Definition at line 712 of file matrix.cpp.

References c, cols(), m, matrix(), r, and rows().

Referenced by add_indexed(), and contract_with().

◆ determinant()

ex GiNaC::matrix::determinant ( unsigned  algo = determinant_algo::automatic) const

Determinant of square matrix.

This routine doesn't actually calculate the determinant, it only implements some heuristics about which algorithm to run. If all the elements of the matrix are elements of an integral domain the determinant is also in that integral domain and the result is expanded only. If one or more elements are from a quotient field the determinant is usually also in that quotient field and the result is normalized before it is returned. This implies that the determinant of the symbolic 2x2 matrix [[a/(a-b),1],[b/(a-b),1]] is returned as unity. (In this respect, it behaves like MapleV and unlike Mathematica.)

Parameters
algoallows to chose an algorithm
Returns
the determinant as a new expression
Exceptions
logic_error(matrix not square)
See also
determinant_algo

Definition at line 737 of file matrix.cpp.

References GiNaC::_ex0, GiNaC::determinant_algo::automatic, GiNaC::determinant_algo::bareiss, c, col, GiNaC::info_flags::crational_polynomial, determinant_minor(), GiNaC::determinant_algo::divfree, division_free_elimination(), fraction_free_elimination(), GiNaC::determinant_algo::gauss, gauss_elimination(), GINAC_ASSERT, GiNaC::ex::info(), GiNaC::ex::is_zero(), GiNaC::is_zero(), GiNaC::determinant_algo::laplace, m, matrix(), GiNaC::ex::normal(), GiNaC::info_flags::numeric, GiNaC::permutation_sign(), r, GiNaC::info_flags::rational_function, and row.

Referenced by charpoly(), and GiNaC::tensepsilon::contract_with().

◆ trace()

ex GiNaC::matrix::trace ( ) const

Trace of a matrix.

The result is normalized if it is in some quotient field and expanded only otherwise. This implies that the trace of the symbolic 2x2 matrix [[a/(a-b),x],[y,b/(b-a)]] is recognized to be unity.

Returns
the sum of diagonal elements
Exceptions
logic_error(matrix not square)

Definition at line 866 of file matrix.cpp.

References col, GiNaC::info_flags::crational_polynomial, GiNaC::ex::expand(), GiNaC::ex::info(), m, GiNaC::ex::normal(), r, GiNaC::info_flags::rational_function, and row.

Referenced by charpoly(), and eval_indexed().

◆ charpoly()

ex GiNaC::matrix::charpoly ( const ex lambda) const

Characteristic Polynomial.

Following mathematica notation the characteristic polynomial of a matrix M is defined as the determinant of (M - lambda * 1) where 1 stands for the unit matrix of the same dimension as M. Note that some CASs define it with a sign inside the determinant which gives rise to an overall sign if the dimension is odd. This method returns the characteristic polynomial collected in powers of lambda as a new expression.

Returns
characteristic polynomial as new expression
Exceptions
logic_error(matrix not square)
See also
matrix::determinant()

Definition at line 894 of file matrix.cpp.

References c, col, GiNaC::ex::collect(), determinant(), GiNaC::basic::ex, m, mul(), GiNaC::info_flags::numeric, poly, r, row, and trace().

◆ inverse() [1/2]

matrix GiNaC::matrix::inverse ( ) const

Inverse of this matrix, with automatic algorithm selection.

Definition at line 939 of file matrix.cpp.

References GiNaC::solve_algo::automatic.

Referenced by pow().

◆ inverse() [2/2]

matrix GiNaC::matrix::inverse ( unsigned  algo) const

Inverse of this matrix.

Parameters
algoselects the algorithm (one of solve_algo)
Returns
the inverted matrix
Exceptions
logic_error(matrix not square)
runtime_error(singular matrix)

Definition at line 950 of file matrix.cpp.

References GiNaC::_ex1, c, col, r, row, and solve().

◆ solve()

matrix GiNaC::matrix::solve ( const matrix vars,
const matrix rhs,
unsigned  algo = solve_algo::automatic 
) const

Solve a linear system consisting of a m x n matrix and a m x p right hand side by applying an elimination scheme to the augmented matrix.

Parameters
varsn x p matrix, all elements must be symbols
rhsm x p matrix
algoselects the solving algorithm
Returns
n x p solution matrix
Exceptions
logic_error(incompatible matrices)
invalid_argument(1st argument must be matrix of symbols)
runtime_error(inconsistent linear system)
See also
solve_algo

Definition at line 995 of file matrix.cpp.

References c, cols(), echelon_form(), GiNaC::basic::info(), m, n, GiNaC::basic::normal(), r, GiNaC::rhs(), rows(), and GiNaC::info_flags::symbol.

Referenced by inverse(), GiNaC::lsolve(), and GiNaC::sqrfree_parfrac().

◆ rank() [1/2]

unsigned GiNaC::matrix::rank ( ) const

Compute the rank of this matrix.

Definition at line 1058 of file matrix.cpp.

References GiNaC::solve_algo::automatic.

◆ rank() [2/2]

unsigned GiNaC::matrix::rank ( unsigned  solve_algo) const

Compute the rank of this matrix using the given algorithm, which should be a member of enum solve_algo.

Definition at line 1065 of file matrix.cpp.

References col, echelon_form(), GINAC_ASSERT, m, r, and row.

◆ is_zero_matrix()

bool GiNaC::matrix::is_zero_matrix ( ) const

Function to check that all elements of the matrix are zero.

Definition at line 1676 of file matrix.cpp.

References m.

◆ determinant_minor()

ex GiNaC::matrix::determinant_minor ( ) const
protected

Recursive determinant for small matrices having at least one symbolic entry.

The basic algorithm, known as Laplace-expansion, is enhanced by some bookkeeping to avoid calculation of the same submatrices ("minors") more than once. According to W.M.Gentleman and S.C.Johnson this algorithm is better than elimination schemes for matrices of sparse multivariate polynomials and also for matrices of dense univariate polynomials if the matrix' dimension is larger than 7.

Returns
the determinant as a new expression (in expanded form)
See also
matrix::determinant()

Definition at line 1096 of file matrix.cpp.

References GiNaC::_ex0, GiNaC::_ex1, c, cols(), GiNaC::ex::expand(), GiNaC::ex::is_zero(), GiNaC::is_zero(), m, n, and r.

Referenced by determinant().

◆ echelon_form()

std::vector< unsigned > GiNaC::matrix::echelon_form ( unsigned  algo,
int  n 
)
protected

◆ gauss_elimination()

int GiNaC::matrix::gauss_elimination ( const bool  det = false)
protected

Perform the steps of an ordinary Gaussian elimination to bring the m x n matrix into an upper echelon form.

The algorithm is ok for matrices with numeric coefficients but quite unsuited for symbolic matrices.

Parameters
detmay be set to true to save a lot of space if one is only interested in the diagonal elements (i.e. for calculating determinants). The others are set to zero in this case.
Returns
sign is 1 if an even number of rows was swapped, -1 if an odd number of rows was swapped and 0 if the matrix is singular.

Definition at line 1269 of file matrix.cpp.

References GiNaC::_ex0, c, cols(), GiNaC::basic::ensure_if_modifiable(), GINAC_ASSERT, GiNaC::basic::info(), GiNaC::is_zero(), m, n, GiNaC::ex::normal(), GiNaC::info_flags::numeric, pivot(), r, and rows().

Referenced by determinant(), and echelon_form().

◆ division_free_elimination()

int GiNaC::matrix::division_free_elimination ( const bool  det = false)
protected

Perform the steps of division free elimination to bring the m x n matrix into an upper echelon form.

Parameters
detmay be set to true to save a lot of space if one is only interested in the diagonal elements (i.e. for calculating determinants). The others are set to zero in this case.
Returns
sign is 1 if an even number of rows was swapped, -1 if an odd number of rows was swapped and 0 if the matrix is singular.

Definition at line 1441 of file matrix.cpp.

References GiNaC::_ex0, c, cols(), GiNaC::basic::ensure_if_modifiable(), GINAC_ASSERT, m, n, pivot(), r, and rows().

Referenced by determinant(), and echelon_form().

◆ fraction_free_elimination()

int GiNaC::matrix::fraction_free_elimination ( const bool  det = false)
protected

Perform the steps of Bareiss' one-step fraction free elimination to bring the matrix into an upper echelon form.

Fraction free elimination means that divide is used straightforwardly, without computing GCDs first. This is possible, since we know the divisor at each step.

Parameters
detmay be set to true to save a lot of space if one is only interested in the last element (i.e. for calculating determinants). The others are set to zero in this case.
Returns
sign is 1 if an even number of rows was swapped, -1 if an odd number of rows was swapped and 0 if the matrix is singular.

Definition at line 1495 of file matrix.cpp.

References GiNaC::_ex0, GiNaC::_ex1, c, cols(), GiNaC::divide(), GiNaC::basic::ensure_if_modifiable(), GiNaC::basic::expand(), GINAC_ASSERT, GiNaC::is_zero(), m, n, GiNaC::subs_options::no_pattern, GiNaC::ex::normal(), GiNaC::ex::numer_denom(), GiNaC::ex::op(), r, rows(), subs(), and GiNaC::ex::to_rational().

Referenced by determinant(), and echelon_form().

◆ markowitz_elimination()

std::vector< unsigned > GiNaC::matrix::markowitz_elimination ( unsigned  n)
protected

Definition at line 1326 of file matrix.cpp.

References GiNaC::_ex0, c, col, GINAC_ASSERT, GiNaC::ex::is_zero(), GiNaC::is_zero(), k, m, n, GiNaC::basic::normal(), r, row, and std::swap().

Referenced by echelon_form().

◆ pivot()

int GiNaC::matrix::pivot ( unsigned  ro,
unsigned  co,
bool  symbolic = true 
)
protected

Partial pivoting method for matrix elimination schemes.

Usual pivoting (symbolic==false) returns the index to the element with the largest absolute value in column ro and swaps the current row with the one where the element was found. With (symbolic==true) it does the same thing with the first non-zero element.

Parameters
rois the row from where to begin
cois the column to be inspected
symbolicsignal if we want the first non-zero element to be pivoted (true) or the one with the largest absolute value (false).
Returns
0 if no interchange occurred, -1 if all are zero (usually signaling a degeneracy) and positive integer k means that rows ro and k were swapped.

Definition at line 1636 of file matrix.cpp.

References GiNaC::abs(), c, col, GiNaC::basic::ensure_if_modifiable(), GiNaC::basic::expand(), GINAC_ASSERT, GiNaC::numeric::is_zero(), GiNaC::is_zero(), k, m, row, and GiNaC::swap().

Referenced by division_free_elimination(), and gauss_elimination().

◆ print_elements()

void GiNaC::matrix::print_elements ( const print_context c,
const char *  row_start,
const char *  row_end,
const char *  row_sep,
const char *  col_sep 
) const
protected

Definition at line 168 of file matrix.cpp.

References c, col, m, and row.

Referenced by do_print(), do_print_latex(), and do_print_python_repr().

◆ do_print()

void GiNaC::matrix::do_print ( const print_context c,
unsigned  level 
) const
protected

Definition at line 184 of file matrix.cpp.

References c, and print_elements().

◆ do_print_latex()

void GiNaC::matrix::do_print_latex ( const print_latex c,
unsigned  level 
) const
protected

Definition at line 191 of file matrix.cpp.

References c, col, and print_elements().

◆ do_print_python_repr()

void GiNaC::matrix::do_print_python_repr ( const print_python_repr c,
unsigned  level 
) const
protected

Definition at line 198 of file matrix.cpp.

References c, and print_elements().

Member Data Documentation

◆ row

unsigned GiNaC::matrix::row
protected

◆ col

unsigned GiNaC::matrix::col
protected

◆ m

exvector GiNaC::matrix::m
protected

The documentation for this class was generated from the following files:

This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.