]> www.ginac.de Git - ginac.git/commitdiff
added symbolic_matrix()
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 21 Nov 2002 20:48:57 +0000 (20:48 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 21 Nov 2002 20:48:57 +0000 (20:48 +0000)
ginac/matrix.cpp
ginac/matrix.h

index 8daa11db0fab78332effeec157ed16fb17b4294f..eaf4468a33742248ea252add319d5a522e6bc5d3 100644 (file)
@@ -20,7 +20,9 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <string>
 #include <iostream>
 #include <iostream>
+#include <sstream>
 #include <algorithm>
 #include <map>
 #include <stdexcept>
 #include <algorithm>
 #include <map>
 #include <stdexcept>
@@ -229,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 |
                        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
 }
 
 ex matrix::subs(const lst & ls, const lst & lr, bool no_pattern) const
@@ -1454,15 +1456,15 @@ ex lst_to_matrix(const lst & l)
                        cols = l.op(i).nops();
 
        // Allocate and fill matrix
                        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<rows; i++)
                for (j=0; j<cols; j++)
                        if (l.op(i).nops() > j)
        for (i=0; i<rows; i++)
                for (j=0; j<cols; j++)
                        if (l.op(i).nops() > j)
-                               m(i, j) = l.op(i).op(j);
+                               M(i, j) = l.op(i).op(j);
                        else
                        else
-                               m(i, j) = _ex0;
-       return m;
+                               M(i, j) = _ex0;
+       return M;
 }
 
 ex diag_matrix(const lst & l)
 }
 
 ex diag_matrix(const lst & l)
@@ -1485,4 +1487,41 @@ ex unit_matrix(unsigned r, unsigned c)
        return Id;
 }
 
        return Id;
 }
 
+ex symbolic_matrix(unsigned r, unsigned c, const std::string & base_name, const std::string & tex_base_name)
+{
+       matrix &M = *new matrix(r, c);
+       M.setflag(status_flags::dynallocated | status_flags::evaluated);
+
+       bool long_format = (r > 10 || c > 10);
+       bool single_row = (r == 1 || c == 1);
+
+       for (unsigned i=0; i<r; i++) {
+               for (unsigned j=0; j<c; j++) {
+                       std::ostringstream s1, s2;
+                       s1 << base_name;
+                       s2 << tex_base_name << "_{";
+                       if (single_row) {
+                               if (c == 1) {
+                                       s1 << i;
+                                       s2 << i << '}';
+                               } else {
+                                       s1 << j;
+                                       s2 << j << '}';
+                               }
+                       } else {
+                               if (long_format) {
+                                       s1 << '_' << i << '_' << j;
+                                       s2 << i << ';' << j << "}";
+                               } else {
+                                       s1 << i << j;
+                                       s2 << i << j << '}';
+                               }
+                       }
+                       M(i, j) = symbol(s1.str(), s2.str());
+               }
+       }
+
+       return M;
+}
+
 } // namespace GiNaC
 } // namespace GiNaC
index 518684ca186f5f443f07e8c2b0ac74de2bea95d6..b0b582d7580f777b9949d43a8d222fc403a4e967 100644 (file)
@@ -24,6 +24,7 @@
 #define __GINAC_MATRIX_H__
 
 #include <vector>
 #define __GINAC_MATRIX_H__
 
 #include <vector>
+#include <string>
 #include "basic.h"
 #include "ex.h"
 
 #include "basic.h"
 #include "ex.h"
 
@@ -144,13 +145,23 @@ extern ex lst_to_matrix(const lst & l);
 /** Convert list of diagonal elements to matrix. */
 extern ex diag_matrix(const lst & l);
 
 /** Convert list of diagonal elements to matrix. */
 extern ex diag_matrix(const lst & l);
 
-/** Create a r times c unit matrix. */
+/** Create an r times c unit matrix. */
 extern ex unit_matrix(unsigned r, unsigned c);
 
 /** Create a x times x unit matrix. */
 inline ex unit_matrix(unsigned x)
 { return unit_matrix(x, x); }
 
 extern ex unit_matrix(unsigned r, unsigned c);
 
 /** Create a x times x unit matrix. */
 inline ex unit_matrix(unsigned x)
 { return unit_matrix(x, x); }
 
+/** Create an r times c matrix of newly generated symbols consisting of the
+ *  given base name plus the numeric row/column position of each element.
+ *  The base name for LaTeX output is specified separately. */
+extern ex symbolic_matrix(unsigned r, unsigned c, const std::string & base_name, const std::string & tex_base_name);
+
+/** Create an r times c matrix of newly generated symbols consisting of the
+ *  given base name plus the numeric row/column position of each element. */
+inline ex symbolic_matrix(unsigned r, unsigned c, const std::string & base_name)
+{ return symbolic_matrix(r, c, base_name, base_name); }
+
 } // namespace GiNaC
 
 #endif // ndef __GINAC_MATRIX_H__
 } // namespace GiNaC
 
 #endif // ndef __GINAC_MATRIX_H__