* corresponding ``.templates.h'' file and instantiate the respective
* class yourself.
*
- * @author Guido Kanschat, Franz-Theo Suttmeier, Wolfgang Bangerth
+ * @author Guido Kanschat, Franz-Theo Suttmeier, Wolfgang Bangerth, 1993-2001
*/
template<typename number>
class FullMatrix : public Subscriptor
FullMatrix (const unsigned int rows, const unsigned int cols);
/**
- * Copy constructor. Be very careful with
- * this constructor, since it may take a
- * huge amount of computing time for large
- * matrices!!
+ * Copy constructor. This constructor does
+ * a deep copy of the matrix. Therefore,
+ * it poses an efficiency problem.
*/
FullMatrix (const FullMatrix&);
+ /**
+ * Constructor initializing from
+ * an array of numbers. The array
+ * is arranged line by line. No
+ * range checking is performed.
+ */
+ FullMatrix (const unsigned int rows,
+ const unsigned int cols,
+ const number* entries);
+
+
/**
* Destructor. Release all memory.
*/
void print (ostream& s, int width=5, int precision=2) const;
/**
- * Print the matrix in the usual format,
- * i.e. as a matrix and not as a list of
- * nonzero elements. For better
- * readability, zero elements
- * are displayed as empty space.
+ * Print the matrix in the usual
+ * format, i.e. as a matrix and
+ * not as a list of nonzero
+ * elements. For better
+ * readability, elements not in
+ * the matrix are displayed as
+ * empty space, while matrix
+ * elements which are explicitely
+ * set to zero are displayed as
+ * such.
+ *
+ * The parameters allow for a
+ * flexible setting of the output
+ * format: @p{precision} and
+ * @p{scientific} are used to
+ * determine the number format,
+ * where @p{scientific} = @p{false}
+ * means fixed point notation. A
+ * zero entry for @p{width} makes
+ * the function compute a width,
+ * but it may be changed to a
+ * positive value, if output is
+ * crude.
+ *
+ * Additionally, a character for
+ * an empty value may be
+ * specified.
*
- * Each entry is printed in scientific
- * format, with one pre-comma digit and
- * the number of digits given by
- * @p{precision} after the comma, with one
- * space following.
- * The precision defaults to four, which
- * suffices for most cases. The precision
- * and output format are @em{not}
- * properly reset to the old values
- * when the function exits.
+ * Finally, the whole matrix can
+ * be multiplied with a common
+ * denominator to produce more
+ * readable output, even
+ * integers.
*
- * You should be aware that this function
+ * This function
* may produce @em{large} amounts of
* output if applied to a large matrix!
- * Be careful with it.
*/
void print_formatted (ostream &out,
- const unsigned int presicion=3) const;
+ const unsigned int presicion=3,
+ const bool scientific = true,
+ const unsigned int width = 0,
+ const char *zero_string = " ",
+ const double denominator = 1.) const;
/**
* Determine an estimate for the
};
+template <typename number>
+FullMatrix<number>::FullMatrix (const unsigned int m,
+ const unsigned int n,
+ const number* entries) :
+ val (0),
+ dim_range (0),
+ dim_image (0),
+ val_size (0)
+{
+ reinit (m,n);
+
+ if (dim_range*dim_image != 0)
+ copy (entries, entries+dim_image*dim_range, val);
+};
+
+
template <typename number>
FullMatrix<number>::FullMatrix (const FullMatrix &m) :
Subscriptor (),
template <typename number>
void
-FullMatrix<number>::print_formatted (ostream &out, const unsigned int precision) const
+FullMatrix<number>::print_formatted (ostream &out,
+ const unsigned int precision,
+ bool scientific,
+ unsigned int width,
+ const char* zero_string,
+ const double denominator) const
{
Assert (val != 0, ExcEmptyMatrix());
- out.precision (precision);
- out.setf (ios::scientific, ios::floatfield); // set output format
+ unsigned int old_precision = out.precision (precision);
+ if (scientific)
+ {
+ out.setf (ios::scientific, ios::floatfield);
+ if (!width)
+ width = precision+7;
+ } else {
+ out.setf (ios::fixed, ios::floatfield);
+ if (!width)
+ width = precision+2;
+ }
for (unsigned int i=0; i<m(); ++i)
{
for (unsigned int j=0; j<n(); ++j)
if (el(i,j) != 0)
- out << setw(precision+7)
- << el(i,j) << ' ';
+ out << setw(width)
+ << el(i,j) * denominator << ' ';
else
- out << setw(precision+8) << " ";
+ out << setw(width) << zero_string << ' ';
out << endl;
};
AssertThrow (out, ExcIO());
-
+
+ out.precision(old_precision);
out.setf (0, ios::floatfield); // reset output format
};
#include <lac/full_matrix.h>
#include <lac/eigen.h>
+const double entries[9] = { 11,12,13,21,22,23,31,32,33 };
+
// Create a positive definite random matrix
void random_matrix(FullMatrix<double>& A)
deallog.attach(logfile);
deallog.depth_console(0);
srand(3391466);
+
+ FullMatrix<double> T(3,3,entries);
+ T.print_formatted(logfile, 0, false);
for (unsigned int i=1;i<10;++i)
{
Vector<double> u(5);
GrowingVectorMemory<Vector<double> > mem;
- SolverControl control (500,1.e-8, false, true);
+ SolverControl control (500,1.e-8, false, false);
if (true)
{
+11. 12. 13.
+21. 22. 23.
+31. 32. 33.
DEAL::Inverse(dim=1):
DEAL::Inverse(dim=2):
DEAL::Inverse(dim=3):
4.093e-01 6.399e-01 1.636e+00 2.203e-01 -2.551e-01
-3.813e-02 -5.962e-02 2.203e-01 4.552e+00 5.184e-01
4.415e-02 6.903e-02 -2.551e-01 5.184e-01 4.400e+00
-DEAL:Power method::Starting
-DEAL:Power method::Convergence step 21
DEAL::Eigen
-DEAL:Power method::Starting
-DEAL:Power method::Convergence step 27
DEAL::Eigen
6.460e-01 9.460e-02 -2.046e-01 1.907e-02 -2.208e-02
9.460e-02 4.235e-01 -1.951e-01 1.817e-02 -2.104e-02
-2.046e-01 -1.951e-01 7.536e-01 -4.693e-02 5.433e-02
1.907e-02 1.817e-02 -4.693e-02 2.257e-01 -2.980e-02
-2.208e-02 -2.104e-02 5.433e-02 -2.980e-02 2.345e-01
-DEAL:Power method::Starting
-DEAL:Power method::Convergence step 17
DEAL::Eigen
-DEAL:Power method::Starting
-DEAL:Power method::Convergence step 177
DEAL::Eigen
DEAL::GrowingVectorMemory:Overall allocated vectors: 8
DEAL::GrowingVectorMemory:Maximum allocated vectors: 2