#include "utils.h"
#include "debugmsg.h"
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
GINAC_IMPLEMENT_REGISTERED_CLASS(matrix, basic)
debugmsg("matrix destructor",LOGLEVEL_DESTRUCT);
}
-matrix::matrix(matrix const & other)
+matrix::matrix(const matrix & other)
{
debugmsg("matrix copy constructor",LOGLEVEL_CONSTRUCT);
copy(other);
}
-matrix const & matrix::operator=(matrix const & other)
+const matrix & matrix::operator=(const matrix & other)
{
debugmsg("matrix operator=",LOGLEVEL_ASSIGNMENT);
if (this != &other) {
// protected
-void matrix::copy(matrix const & other)
+void matrix::copy(const matrix & other)
{
inherited::copy(other);
row=other.row;
// protected
/** Ctor from representation, for internal use only. */
-matrix::matrix(unsigned r, unsigned c, exvector const & m2)
+matrix::matrix(unsigned r, unsigned c, const exvector & m2)
: inherited(TINFO_matrix), row(r), col(c), m(m2)
{
debugmsg("matrix constructor from unsigned,unsigned,exvector",LOGLEVEL_CONSTRUCT);
}
/** returns matrix entry at position (i/col, i%col). */
-ex & matrix::let_op(int const i)
+ex matrix::op(int i) const
+{
+ return m[i];
+}
+
+/** returns matrix entry at position (i/col, i%col). */
+ex & matrix::let_op(int i)
{
return m[i];
}
/** Search ocurrences. A matrix 'has' an expression if it is the expression
* itself or one of the elements 'has' it. */
-bool matrix::has(ex const & other) const
+bool matrix::has(const ex & other) const
{
GINAC_ASSERT(other.bp!=0);
// protected
-int matrix::compare_same_type(basic const & other) const
+int matrix::compare_same_type(const basic & other) const
{
GINAC_ASSERT(is_exactly_of_type(other, matrix));
- matrix const & o=static_cast<matrix &>(const_cast<basic &>(other));
+ const matrix & o=static_cast<matrix &>(const_cast<basic &>(other));
// compare number of rows
if (row != o.rows()) {
/** Sum of matrices.
*
* @exception logic_error (incompatible matrices) */
-matrix matrix::add(matrix const & other) const
+matrix matrix::add(const matrix & other) const
{
if (col != other.col || row != other.row) {
throw (std::logic_error("matrix::add(): incompatible matrices"));
/** Difference of matrices.
*
* @exception logic_error (incompatible matrices) */
-matrix matrix::sub(matrix const & other) const
+matrix matrix::sub(const matrix & other) const
{
if (col != other.col || row != other.row) {
throw (std::logic_error("matrix::sub(): incompatible matrices"));
/** Product of matrices.
*
* @exception logic_error (incompatible matrices) */
-matrix matrix::mul(matrix const & other) const
+matrix matrix::mul(const matrix & other) const
{
if (col != other.row) {
throw (std::logic_error("matrix::mul(): incompatible matrices"));
* @param ro row of element
* @param co column of element
* @exception range_error (index out of range) */
-ex const & matrix::operator() (unsigned ro, unsigned co) const
+const ex & matrix::operator() (unsigned ro, unsigned co) const
{
if (ro<0 || ro>=row || co<0 || co>=col) {
throw (std::range_error("matrix::operator(): index out of range"));
// Compute the sign of a permutation of a vector of things, used internally
// by determinant_symbolic_perm() where it is instantiated for int.
-template <class T>
+template <typename T>
int permutation_sign(vector<T> s)
{
if (s.size() < 2)
* @return characteristic polynomial as new expression
* @exception logic_error (matrix not square)
* @see matrix::determinant() */
-ex matrix::charpoly(ex const & lambda) const
+ex matrix::charpoly(const ex & lambda) const
{
if (row != col) {
throw (std::logic_error("matrix::charpoly(): matrix not square"));
* @param rhs m x p matrix
* @exception logic_error (incompatible matrices)
* @exception runtime_error (singular matrix) */
-matrix matrix::fraction_free_elim(matrix const & vars,
- matrix const & rhs) const
+matrix matrix::fraction_free_elim(const matrix & vars,
+ const matrix & rhs) const
{
if ((row != rhs.row) || (col != vars.row) || (rhs.col != vars.col)) {
throw (std::logic_error("matrix::solve(): incompatible matrices"));
matrix a(*this); // make a copy of the matrix
matrix b(rhs); // make a copy of the rhs vector
+
+ /*
+ cout << "before" << endl;
+ cout << "a=" << a << endl;
+ cout << "b=" << b << endl;
+ */
// given an m x n matrix a, reduce it to upper echelon form
unsigned m=a.row;
zero_in_last_row=zero_in_this_row;
}
#endif // def DO_GINAC_ASSERT
+
+ /*
+ cout << "after" << endl;
+ cout << "a=" << a << endl;
+ cout << "b=" << b << endl;
+ */
// assemble solution
matrix sol(n,1);
cout << vars.ffe_get(c,1) << "->" << sol.ffe_get(c,1) << endl;
}
*/
+
+ // cout << "sol=" << sol << endl;
#ifdef DO_GINAC_ASSERT
// test solution with echelon matrix
}
/** Solve simultaneous set of equations. */
-matrix matrix::solve(matrix const & v) const
+matrix matrix::solve(const matrix & v) const
{
if (!(row == col && col == v.row)) {
throw (std::logic_error("matrix::solve(): incompatible matrices"));
//////////
const matrix some_matrix;
-type_info const & typeid_matrix=typeid(some_matrix);
+const type_info & typeid_matrix=typeid(some_matrix);
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
} // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC