X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fmatrix.cpp;h=d82abab790356326efc060b7f88749285ad88c49;hp=3d735fe46689aa57fc0d973a0b8588e07f2049f8;hb=1d07d8ac9fb47c51aa19a84df6c8c5fee5dd5105;hpb=fbdd5eefb7188778ca9c04b5bee08223609b880f diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index 3d735fe4..d82abab7 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -3,7 +3,7 @@ * Implementation of symbolic matrices */ /* - * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include +#include #include #include #include @@ -147,23 +149,44 @@ void matrix::print(const print_context & c, unsigned level) const } else { - c.s << "["; - for (unsigned y=0; y(c)) + c.s << class_name() << '('; + + if (is_a(c)) + c.s << "\\left(\\begin{array}{" << std::string(col,'c') << "}"; + else c.s << "["; - for (unsigned x=0; x(c)) + c.s << "["; + for (unsigned co=0; co(c)) + c.s << "&"; + else + c.s << ","; + } else { + if (!is_a(c)) + c.s << "]"; + } + } + if (ro(c)) + c.s << "\\\\"; + else + c.s << ","; } - m[col*(y+1)-1].print(c); - c.s << "],"; - } - c.s << "["; - for (unsigned x=0; x(c)) + c.s << "\\end{array}\\right)"; + else + c.s << "]"; + + if (is_a(c)) + c.s << ')'; } } @@ -208,7 +231,7 @@ ex matrix::eval(int level) const m2[r*col+c] = m[r*col+c].eval(level); return (new matrix(row, col, m2))->setflag(status_flags::dynallocated | - status_flags::evaluated ); + status_flags::evaluated); } ex matrix::subs(const lst & ls, const lst & lr, bool no_pattern) const @@ -599,17 +622,19 @@ matrix matrix::pow(const ex & expn) const matrix C(row,col); for (unsigned r=0; r(this->m[k*col+co])); + GINAC_ASSERT(is_exactly_a(this->m[k*col+co])); unsigned kmax = k+1; numeric mmax = abs(ex_to(m[kmax*col+co])); while (kmax(this->m[kmax*col+co])); + GINAC_ASSERT(is_exactly_a(this->m[kmax*col+co])); numeric tmp = ex_to(this->m[kmax*col+co]); if (abs(tmp) > mmax) { mmax = tmp; @@ -1431,15 +1456,15 @@ ex lst_to_matrix(const lst & l) cols = l.op(i).nops(); // Allocate and fill matrix - matrix &m = *new matrix(rows, cols); - m.setflag(status_flags::dynallocated); + matrix &M = *new matrix(rows, cols); + M.setflag(status_flags::dynallocated); for (i=0; i j) - m(i, j) = l.op(i).op(j); + M(i, j) = l.op(i).op(j); else - m(i, j) = _ex0; - return m; + M(i, j) = _ex0; + return M; } ex diag_matrix(const lst & l) @@ -1454,4 +1479,51 @@ ex diag_matrix(const lst & l) return m; } +ex unit_matrix(unsigned r, unsigned c) +{ + matrix &Id = *new matrix(r, c); + Id.setflag(status_flags::dynallocated); + for (unsigned i=0; i 10 || c > 10); + bool single_row = (r == 1 || c == 1); + + for (unsigned i=0; i