Heidelberg Educational Numerics Library Version 0.24 (from 9 September 2011)
Public Types | Public Member Functions | Related Functions

hdnum::DenseMatrix< REAL > Class Template Reference

Class with mathematical matrix operations. More...

#include <densematrix.hh>

List of all members.

Public Types

typedef std::size_t size_type
 Type used for array indices.
typedef std::vector< REAL > VType
typedef VType::const_iterator ConstVectorIterator
typedef VType::iterator VectorIterator

Public Member Functions

 DenseMatrix (const std::size_t _rows, const std::size_t _cols, const REAL def_val=0)
void addNewRow (const hdnum::Vector< REAL > &rowvector)
size_t rowsize () const
 get number of rows of the matrix
size_t colsize () const
 get number of columns of the matrix
bool scientific () const
void scientific (bool b) const
 Switch between floating point (default=true) and fixed point (false) display.
std::size_t iwidth () const
 get index field width for pretty-printing
std::size_t width () const
 get data field width for pretty-printing
std::size_t precision () const
 get data precision for pretty-printing
void iwidth (std::size_t i) const
 set index field width for pretty-printing
void width (std::size_t i) const
 set data field width for pretty-printing
void precision (std::size_t i) const
 set data precision for pretty-printing
REAL & operator() (const std::size_t row, const std::size_t col)
 (i,j)-operator for accessing entries of a (m x n)-matrix directly
const REAL & operator() (const std::size_t row, const std::size_t col) const
const ConstVectorIterator operator[] (const std::size_t row) const
VectorIterator operator[] (const std::size_t row)
 [i][j]-operator for accessing entries of a (m x n)-matrix directly
DenseMatrixoperator= (const DenseMatrix &A)
 assignment operator
DenseMatrixoperator= (const REAL value)
 assignment from a scalar value
DenseMatrix sub (size_type i, size_type j, size_type rows, size_type cols)
 Submatrix extraction.
DenseMatrixoperator+= (const DenseMatrix &B)
 Addition assignment.
DenseMatrixoperator-= (const DenseMatrix &B)
 Subtraction assignment.
DenseMatrixoperator*= (const REAL s)
 Scalar multiplication assignment.
DenseMatrixoperator/= (const REAL s)
 Scalar division assignment.
void update (const REAL s, const DenseMatrix &B)
 Scaled update of a Matrix.
template<class V >
void mv (Vector< V > &y, const Vector< V > &x) const
 matrix vector product y = A*x
template<class V >
void umv (Vector< V > &y, const Vector< V > &x) const
 update matrix vector product y += A*x
template<class V >
void umv (Vector< V > &y, const V &s, const Vector< V > &x) const
 update matrix vector product y += sA*x
void mm (const DenseMatrix< REAL > &A, const DenseMatrix< REAL > &B)
 assign to matrix product C = A*B to matrix C
void umm (const DenseMatrix< REAL > &A, const DenseMatrix< REAL > &B)
 add matrix product A*B to matrix C
void sc (const Vector< REAL > &x, std::size_t k)
 set column: make x the k'th column of A
void sr (const Vector< REAL > &x, std::size_t k)
 set row: make x the k'th row of A
REAL norm_infty () const
 compute row sum norm
REAL norm_1 () const
 compute column sum norm
Vector< REAL > operator* (const Vector< REAL > &x)
 vector = matrix * vector
DenseMatrix operator* (const DenseMatrix &x) const
 matrix = matrix * matrix
DenseMatrix operator+ (const DenseMatrix &x) const
 matrix = matrix + matrix
DenseMatrix operator- (const DenseMatrix &x) const
 matrix = matrix - matrix

Related Functions

(Note that these are not member functions.)
template<class T >
void identity (DenseMatrix< T > &A)
template<typename REAL >
void spd (DenseMatrix< REAL > &A)
template<typename REAL >
void vandermonde (DenseMatrix< REAL > &A, const Vector< REAL > x)
template<typename REAL >
void readMatrixFromFile (const std::string &filename, DenseMatrix< REAL > &A)
 Read matrix from a text file.

Detailed Description

template<typename REAL>
class hdnum::DenseMatrix< REAL >

Class with mathematical matrix operations.


Member Function Documentation

template<typename REAL>
size_t hdnum::DenseMatrix< REAL >::colsize ( ) const [inline]

get number of columns of the matrix

Example:

      hdnum::DenseMatrix<double> A(4,5);
      size_t nColumns = A.colsize();
      std::cout << "Matrix A has " << nColumns << " columns." << std::endl;

Output:

      Matrix A has 5 columns.
	  
template<typename REAL>
void hdnum::DenseMatrix< REAL >::mm ( const DenseMatrix< REAL > &  A,
const DenseMatrix< REAL > &  B 
) [inline]

assign to matrix product C = A*B to matrix C

Implements C = A*B where A and B are matrices

Parameters:
[in]xconstant reference to a DenseMatrix
[in]xconstant reference to a DenseMatrix

Example:

      hdnum::DenseMatrix<double> A(2,6,1.0);
      hdnum::DenseMatrix<double> B(6,3,-1.0);

      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(6);          // use at least 6 columns for displaying matrix entries
      A.precision(3);      // display 3 digits behind the point 

      std::cout << "A =" << A << std::endl;
      std::cout << "B =" << B << std::endl;

      hdnum::DenseMatrix<double> C(2,3);
      C.mm(A,B);
      std::cout << "C = A*B =" << C << std::endl;

Output:

      A =
      0      1      2      3      4      5 
      0   1.000  1.000  1.000  1.000  1.000  1.000 
      1   1.000  1.000  1.000  1.000  1.000  1.000 

      B =
      0      1      2 
      0  -1.000 -1.000 -1.000 
      1  -1.000 -1.000 -1.000 
      2  -1.000 -1.000 -1.000 
      3  -1.000 -1.000 -1.000 
      4  -1.000 -1.000 -1.000 
      5  -1.000 -1.000 -1.000 

      C = A*B =
      0      1      2 
      0  -6.000 -6.000 -6.000 
      1  -6.000 -6.000 -6.000 
	  
template<typename REAL>
template<class V >
void hdnum::DenseMatrix< REAL >::mv ( Vector< V > &  y,
const Vector< V > &  x 
) const [inline]

matrix vector product y = A*x

Implements y = A*x where x and y are a vectors and A is a matrix

Parameters:
[in]yreference to the resulting Vector
[in]xconstant reference to a Vector

Example:

      hdnum::Vector<double> x(3,10.0);
      hdnum::Vector<double> y(2);
      hdnum::DenseMatrix<double> A(2,3,1.0);

      x.scientific(false); // fixed point representation for all Vector objects
      A.scientific(false); // fixed point representation for all DenseMatrix objects

      std::cout << "A =" << A << std::endl;
      std::cout << "x =" << x << std::endl;
      A.mv(y,x);
      std::cout << "y = A*x =" << y << std::endl;

Output:

      A =
      0          1          2 
      0       1.000      1.000      1.000 
      1       1.000      1.000      1.000 

      x =
      [ 0]     10.0000000
      [ 1]     10.0000000
      [ 2]     10.0000000

      y = A*x =
      [ 0]     30.0000000
      [ 1]     30.0000000
	  
template<typename REAL>
REAL& hdnum::DenseMatrix< REAL >::operator() ( const std::size_t  row,
const std::size_t  col 
) [inline]

(i,j)-operator for accessing entries of a (m x n)-matrix directly

Parameters:
[in]irow index (0...m-1)
[in]jcolumn index (0...n-1)

Example:

      hdnum::DenseMatrix<double> A(4,4);
      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(3);

      identity(A);  // Defines the identity matrix of the same dimension
      std::cout << "A=" << A << std::endl;

      std::cout << "reading A(0,0)=" << A(0,0) << std::endl;

      std::cout << "resetting A(0,0) and A(2,3)..." << std::endl;
      A(0,0) = 1.234;
      A(2,3) = 432.1;
  
      std::cout << "A=" << A << std::endl;

Output:

      A=
      0        1        2        3 
      0     1.000    0.000    0.000    0.000 
      1     0.000    1.000    0.000    0.000 
      2     0.000    0.000    1.000    0.000 
      3     0.000    0.000    0.000    1.000 

      reading A(0,0)=1.000
      resetting A(0,0) and A(2,3)...
      A=
      0        1        2        3 
      0     1.234    0.000    0.000    0.000 
      1     0.000    1.000    0.000    0.000 
      2     0.000    0.000    1.000  432.100 
      3     0.000    0.000    0.000    1.000 
	  
template<typename REAL>
Vector<REAL> hdnum::DenseMatrix< REAL >::operator* ( const Vector< REAL > &  x) [inline]

vector = matrix * vector

Parameters:
[in]xconstant reference to a Vector

Example:

      hdnum::Vector<double> x(3,4.0);
      hdnum::DenseMatrix<double> A(3,3,2.0);
      hdnum::Vector<double> y(3);

      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(1);
  
      x.scientific(false); // fixed point representation for all Vector objects
      x.width(8);
      x.precision(1);


      std::cout << "A=" << A << std::endl;
      std::cout << "x=" << x << std::endl;
      y=A*x;
      std::cout << "y=A*x" << y << std::endl;

Output:

      A=
      0        1        2 
      0       2.0      2.0      2.0 
      1       2.0      2.0      2.0 
      2       2.0      2.0      2.0 

      x=
      [ 0]     4.0
      [ 1]     4.0
      [ 2]     4.0

      y=A*x
      [ 0]    24.0
      [ 1]    24.0
      [ 2]    24.0
	  
template<typename REAL>
DenseMatrix hdnum::DenseMatrix< REAL >::operator* ( const DenseMatrix< REAL > &  x) const [inline]

matrix = matrix * matrix

Parameters:
[in]xconstant reference to a DenseMatrix

Example:

      hdnum::DenseMatrix<double> A(3,3,2.0);
      hdnum::DenseMatrix<double> B(3,3,4.0);
      hdnum::DenseMatrix<double> C(3,3);

      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(1);

      std::cout << "A=" << A << std::endl;
      std::cout << "B=" << B << std::endl;
      C=A*B;
      std::cout << "C=A*B=" << C << std::endl;

Output:

      A=
      0        1        2 
      0       2.0      2.0      2.0 
      1       2.0      2.0      2.0 
      2       2.0      2.0      2.0 

      B=
      0        1        2 
      0       4.0      4.0      4.0 
      1       4.0      4.0      4.0 
      2       4.0      4.0      4.0 

      C=A*B=
      0        1        2 
      0      24.0     24.0     24.0 
      1      24.0     24.0     24.0 
      2      24.0     24.0     24.0 
	  
template<typename REAL>
DenseMatrix& hdnum::DenseMatrix< REAL >::operator*= ( const REAL  s) [inline]

Scalar multiplication assignment.

Implements A *= s where s is a scalar

Parameters:
[in]sscalar value to multiply with

Example:

          double s = 0.5;
          hdnum::DenseMatrix<double> A(2,3,1.0);
          std::cout << "A=" << A << std::endl;
          A *= s;
          std::cout << "A=" << A << std::endl;

Output:

      A=
      0          1          2 
      0   1.000e+00  1.000e+00  1.000e+00 
      1   1.000e+00  1.000e+00  1.000e+00 

      0.5*A =
      0          1          2 
      0   5.000e-01  5.000e-01  5.000e-01 
      1   5.000e-01  5.000e-01  5.000e-01 
	  
template<typename REAL>
DenseMatrix hdnum::DenseMatrix< REAL >::operator+ ( const DenseMatrix< REAL > &  x) const [inline]

matrix = matrix + matrix

Parameters:
[in]xconstant reference to a DenseMatrix

Example:

      hdnum::DenseMatrix<double> A(3,3,2.0);
      hdnum::DenseMatrix<double> B(3,3,4.0);
      hdnum::DenseMatrix<double> C(3,3);

      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(1);

      std::cout << "A=" << A << std::endl;
      std::cout << "B=" << B << std::endl;
      C=A+B;
      std::cout << "C=A+B=" << C << std::endl;

Output:

      A=
      0        1        2 
      0       2.0      2.0      2.0 
      1       2.0      2.0      2.0 
      2       2.0      2.0      2.0 

      B=
      0        1        2 
      0       4.0      4.0      4.0 
      1       4.0      4.0      4.0 
      2       4.0      4.0      4.0 

      C=A+B=
      0        1        2 
      0       6.0      6.0      6.0 
      1       6.0      6.0      6.0 
      2       6.0      6.0      6.0 
	  
template<typename REAL>
DenseMatrix& hdnum::DenseMatrix< REAL >::operator+= ( const DenseMatrix< REAL > &  B) [inline]

Addition assignment.

Implements A += B matrix addition

Parameters:
[in]Banother Matrix
template<typename REAL>
DenseMatrix hdnum::DenseMatrix< REAL >::operator- ( const DenseMatrix< REAL > &  x) const [inline]

matrix = matrix - matrix

Parameters:
[in]xconstant reference to a DenseMatrix

Example:

      hdnum::DenseMatrix<double> A(3,3,2.0);
      hdnum::DenseMatrix<double> B(3,3,4.0);
      hdnum::DenseMatrix<double> C(3,3);

      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(1);

      std::cout << "A=" << A << std::endl;
      std::cout << "B=" << B << std::endl;
      C=A-B;
      std::cout << "C=A-B=" << C << std::endl;

Output:

      A=
      0        1        2 
      0       2.0      2.0      2.0 
      1       2.0      2.0      2.0 
      2       2.0      2.0      2.0 

      B=
      0        1        2 
      0       4.0      4.0      4.0 
      1       4.0      4.0      4.0 
      2       4.0      4.0      4.0 

      C=A-B=
      0        1        2 
      0      -2.0     -2.0     -2.0 
      1      -2.0     -2.0     -2.0 
      2      -2.0     -2.0     -2.0 
	  
template<typename REAL>
DenseMatrix& hdnum::DenseMatrix< REAL >::operator-= ( const DenseMatrix< REAL > &  B) [inline]

Subtraction assignment.

Implements A -= B matrix subtraction

Parameters:
[in]Banother matrix
template<typename REAL>
DenseMatrix& hdnum::DenseMatrix< REAL >::operator/= ( const REAL  s) [inline]

Scalar division assignment.

Implements A /= s where s is a scalar

Parameters:
[in]sscalar value to multiply with

Example:

          double s = 0.5;
          hdnum::DenseMatrix<double> A(2,3,1.0);
          std::cout << "A=" << A << std::endl;
          A /= s;
          std::cout << "A=" << A << std::endl;

Output:

      A=
      0          1          2 
      0   1.000e+00  1.000e+00  1.000e+00 
      1   1.000e+00  1.000e+00  1.000e+00 

      A/0.5 =
      0          1          2 
      0   2.000e+00  2.000e+00  2.000e+00 
      1   2.000e+00  2.000e+00  2.000e+00 
	  
template<typename REAL>
DenseMatrix& hdnum::DenseMatrix< REAL >::operator= ( const DenseMatrix< REAL > &  A) [inline]

assignment operator

Example:

      hdnum::DenseMatrix<double> A(4,4);
      spd(A);
      hdnum::DenseMatrix<double> B(4,4);
      B = A;
      std::cout << "B=" << B << std::endl;

Output:

      B=
      0          1          2          3 
      0   4.000e+00 -1.000e+00 -2.500e-01 -1.111e-01 
      1  -1.000e+00  4.000e+00 -1.000e+00 -2.500e-01 
      2  -2.500e-01 -1.000e+00  4.000e+00 -1.000e+00 
      3  -1.111e-01 -2.500e-01 -1.000e+00  4.000e+00 
	  
template<typename REAL>
DenseMatrix& hdnum::DenseMatrix< REAL >::operator= ( const REAL  value) [inline]

assignment from a scalar value

Example:

      hdnum::DenseMatrix<double> A(2,3);
      A = 5.432;
      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(3);
      std::cout << "A=" << A << std::endl;

Output:

      A=
      0        1        2 
      0     5.432    5.432    5.432
      1     5.432    5.432    5.432
	  
template<typename REAL>
VectorIterator hdnum::DenseMatrix< REAL >::operator[] ( const std::size_t  row) [inline]

[i][j]-operator for accessing entries of a (m x n)-matrix directly

Parameters:
[in]irow index (0...m-1)
[in]jcolumn index (0...n-1)

Example:

      hdnum::DenseMatrix<double> A(4,4);
      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(3);

      identity(A);  // Defines the identity matrix of the same dimension
      std::cout << "A=" << A << std::endl;

      std::cout << "reading A[0][0]=" << A[0][0] << std::endl;
      std::cout << "resetting A[0][0] and A[2][3]..." << std::endl;
      A[0][0] = 1.234;
      A[2][3] = 432.1;

      std::cout << "A=" << A << std::endl;

Output:

      A=
      0        1        2        3 
      0     1.000    0.000    0.000    0.000 
      1     0.000    1.000    0.000    0.000 
      2     0.000    0.000    1.000    0.000 
      3     0.000    0.000    0.000    1.000 

      reading A[0][0]=1.000
      resetting A[0][0] and A[2][3]...
      A=
      0        1        2        3 
      0     1.234    0.000    0.000    0.000 
      1     0.000    1.000    0.000    0.000 
      2     0.000    0.000    1.000  432.100 
      3     0.000    0.000    0.000    1.000 
	  
template<typename REAL>
size_t hdnum::DenseMatrix< REAL >::rowsize ( ) const [inline]

get number of rows of the matrix

Example:

      hdnum::DenseMatrix<double> A(4,5);
      size_t nRows = A.rowsize();
      std::cout << "Matrix A has " << nRows << " rows." << std::endl;

Output:

      Matrix A has 4 rows.
	  
template<typename REAL>
void hdnum::DenseMatrix< REAL >::sc ( const Vector< REAL > &  x,
std::size_t  k 
) [inline]

set column: make x the k'th column of A

Parameters:
[in]xconstant reference to a Vector
[in]knumber of the column of A to be set

Example:

      hdnum::Vector<double> x(2,434.0);
      hdnum::DenseMatrix<double> A(2,6);

      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(1);
  
      std::cout << "original A=" << A << std::endl;
      A.sc(x,3);   // redefine fourth column of the matrix
      std::cout << "modified A=" << A << std::endl;

Output:

      original A=
      0        1        2        3        4        5 
      0       0.0      0.0      0.0      0.0      0.0      0.0 
      1       0.0      0.0      0.0      0.0      0.0      0.0 

      modified A=
      0        1        2        3        4        5 
      0       0.0      0.0      0.0    434.0      0.0      0.0 
      1       0.0      0.0      0.0    434.0      0.0      0.0 
	  
template<typename REAL>
void hdnum::DenseMatrix< REAL >::scientific ( bool  b) const [inline]

Switch between floating point (default=true) and fixed point (false) display.

Example:

      hdnum::DenseMatrix<double> A(4,4);
      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(3);
      identity(A);  // Defines the identity matrix of the same dimension
      std::cout << "A=" << A << std::endl;

Output:

      A=
      0        1        2        3 
      0     1.000    0.000    0.000    0.000 
      1     0.000    1.000    0.000    0.000 
      2     0.000    0.000    1.000    0.000 
      3     0.000    0.000    0.000    1.000 
	  
template<typename REAL>
void hdnum::DenseMatrix< REAL >::sr ( const Vector< REAL > &  x,
std::size_t  k 
) [inline]

set row: make x the k'th row of A

Parameters:
[in]xconstant reference to a Vector
[in]knumber of the row of A to be set

Example:

      hdnum::Vector<double> x(3,434.0);
      hdnum::DenseMatrix<double> A(3,3);

      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(8);
      A.precision(1);
  
      std::cout << "original A=" << A << std::endl;
      A.sr(x,1);   // redefine second row of the matrix
      std::cout << "modified A=" << A << std::endl;

Output:

      original A=
      0        1        2 
      0       0.0      0.0      0.0 
      1       0.0      0.0      0.0 
      2       0.0      0.0      0.0 

      modified A=
      0        1        2 
      0       0.0      0.0      0.0 
      1     434.0    434.0    434.0 
      2       0.0      0.0      0.0 
	  
template<typename REAL>
DenseMatrix hdnum::DenseMatrix< REAL >::sub ( size_type  i,
size_type  j,
size_type  rows,
size_type  cols 
) [inline]

Submatrix extraction.

Returns a new matrix that is a subset of the components of the given matrix.

Parameters:
[in]ifirst row index of the new matrix
[in]jfirst column index of the new matrix
[in]rowsrow size of the new matrix, i.e. it has components [i,i+rows-1]
[in]colscolumn size of the new matrix, i.e. it has components [j,j+m-1]
template<typename REAL>
void hdnum::DenseMatrix< REAL >::umm ( const DenseMatrix< REAL > &  A,
const DenseMatrix< REAL > &  B 
) [inline]

add matrix product A*B to matrix C

Implements C += A*B where A, B and C are matrices

Parameters:
[in]xconstant reference to a DenseMatrix
[in]xconstant reference to a DenseMatrix

Example:

      hdnum::DenseMatrix<double> A(2,6,1.0);
      hdnum::DenseMatrix<double> B(6,3,-1.0);
      hdnum::DenseMatrix<double> C(2,3,0.5);

      A.scientific(false); // fixed point representation for all DenseMatrix objects
      A.width(6);
      A.precision(3);

      std::cout << "C =" << C << std::endl;
      std::cout << "A =" << A << std::endl;
      std::cout << "B =" << B << std::endl;

      C.umm(A,B);
      std::cout << "C + A*B =" << C << std::endl;

Output:

      C =
      0      1      2 
      0   0.500  0.500  0.500 
      1   0.500  0.500  0.500 

      A =
      0      1      2      3      4      5 
      0   1.000  1.000  1.000  1.000  1.000  1.000 
      1   1.000  1.000  1.000  1.000  1.000  1.000 

      B =
      0      1      2 
      0  -1.000 -1.000 -1.000 
      1  -1.000 -1.000 -1.000 
      2  -1.000 -1.000 -1.000 
      3  -1.000 -1.000 -1.000 
      4  -1.000 -1.000 -1.000 
      5  -1.000 -1.000 -1.000 

      C + A*B =
      0      1      2 
      0  -5.500 -5.500 -5.500 
      1  -5.500 -5.500 -5.500 
	  
template<typename REAL>
template<class V >
void hdnum::DenseMatrix< REAL >::umv ( Vector< V > &  y,
const V &  s,
const Vector< V > &  x 
) const [inline]

update matrix vector product y += sA*x

Implements y += sA*x where s is a scalar value, x and y are a vectors and A is a matrix

Parameters:
[in]yreference to the resulting Vector
[in]sconstant reference to a number type
[in]xconstant reference to a Vector

Example:

      double s=0.5;
      hdnum::Vector<double> x(3,10.0);
      hdnum::Vector<double> y(2,5.0);
      hdnum::DenseMatrix<double> A(2,3,1.0);

      x.scientific(false); // fixed point representation for all Vector objects
      A.scientific(false); // fixed point representation for all DenseMatrix objects

      std::cout << "y =" << y << std::endl;
      std::cout << "A =" << A << std::endl;
      std::cout << "x =" << x << std::endl;
      A.umv(y,s,x);
      std::cout << "y = s*A*x =" << y << std::endl;

Output:

      y =
      [ 0]      5.0000000
      [ 1]      5.0000000

      A =
      0          1          2 
      0       1.000      1.000      1.000 
      1       1.000      1.000      1.000 

      x =
      [ 0]     10.0000000
      [ 1]     10.0000000
      [ 2]     10.0000000

      y = s*A*x =
      [ 0]     20.0000000
      [ 1]     20.0000000
	  
template<typename REAL>
template<class V >
void hdnum::DenseMatrix< REAL >::umv ( Vector< V > &  y,
const Vector< V > &  x 
) const [inline]

update matrix vector product y += A*x

Implements y += A*x where x and y are a vectors and A is a matrix

Parameters:
[in]yreference to the resulting Vector
[in]xconstant reference to a Vector

Example:

      hdnum::Vector<double> x(3,10.0);
      hdnum::Vector<double> y(2,5.0);
      hdnum::DenseMatrix<double> A(2,3,1.0);

      x.scientific(false); // fixed point representation for all Vector objects
      A.scientific(false); // fixed point representation for all DenseMatrix objects

      std::cout << "y =" << y << std::endl;
      std::cout << "A =" << A << std::endl;
      std::cout << "x =" << x << std::endl;
      A.umv(y,x);
      std::cout << "y = A*x =" << y << std::endl;

Output:

      y =
      [ 0]      5.0000000
      [ 1]      5.0000000

      A =
      0          1          2 
      0       1.000      1.000      1.000 
      1       1.000      1.000      1.000 

      x =
      [ 0]     10.0000000
      [ 1]     10.0000000
      [ 2]     10.0000000

      y + A*x =
      [ 0]     35.0000000
      [ 1]     35.0000000
	  
template<typename REAL>
void hdnum::DenseMatrix< REAL >::update ( const REAL  s,
const DenseMatrix< REAL > &  B 
) [inline]

Scaled update of a Matrix.

Implements A += s*B where s is a scalar and B a matrix

Parameters:
[in]sscalar value to multiply with
[in]Banother matrix

Example:

          double s = 0.5;
          hdnum::DenseMatrix<double> A(2,3,1.0);
          hdnum::DenseMatrix<double> B(2,3,2.0);
          A.update(s,B);
          std::cout << "A + s*B =" << A << std::endl;

Output:

      A + s*B =
      0          1          2 
      0       1.500      1.500      1.500 
      1       1.500      1.500      1.500 
	  

Friends And Related Function Documentation

template<class T >
void identity ( DenseMatrix< T > &  A) [related]


Function: make identity matrix

    template<class T>
    inline void identity (DenseMatrix<T> &A)
Parameters:
[in]Areference to a DenseMatrix that shall be filled with entries

Example:

    hdnum::DenseMatrix<double> A(4,4);
    identity(A);

    A.scientific(false); // fixed point representation for all DenseMatrix objects
    A.width(10);
    A.precision(5);

    std::cout << "A=" << A << std::endl;

Output:

    A=
    0          1          2          3 
    0     1.00000    0.00000    0.00000    0.00000 
    1     0.00000    1.00000    0.00000    0.00000 
    2     0.00000    0.00000    1.00000    0.00000 
    3     0.00000    0.00000    0.00000    1.00000 
	
template<typename REAL >
void readMatrixFromFile ( const std::string &  filename,
DenseMatrix< REAL > &  A 
) [related]

Read matrix from a text file.

Parameters:
[in]filenamename of the text file
[in,out]Areference to a DenseMatrix

Example:

    hdnum::DenseMatrix<number> L;
    readMatrixFromFile("matrixL.dat", L );
    std::cout << "L=" << L << std::endl;

Output:

    Contents of "matrixL.dat":
    1.000e+00  0.000e+00  0.000e+00	 
    2.000e+00  1.000e+00  0.000e+00	 
    3.000e+00  2.000e+00  1.000e+00	 

    would give:
    L=
    0          1          2
    0   1.000e+00  0.000e+00  0.000e+00
    1   2.000e+00  1.000e+00  0.000e+00
    2   3.000e+00  2.000e+00  1.000e+00
	
template<typename REAL >
void spd ( DenseMatrix< REAL > &  A) [related]


Function: make a symmetric and positive definite matrix

    template<typename REAL>
    inline void spd (DenseMatrix<REAL> &A)
Parameters:
[in]Areference to a DenseMatrix that shall be filled with entries

Example:

    hdnum::DenseMatrix<double> A(4,4);
    spd(A);

    A.scientific(false); // fixed point representation for all DenseMatrix objects
    A.width(10);
    A.precision(5);

    std::cout << "A=" << A << std::endl;

Output:

    A=
    0          1          2          3 
    0     4.00000   -1.00000   -0.25000   -0.11111 
    1    -1.00000    4.00000   -1.00000   -0.25000 
    2    -0.25000   -1.00000    4.00000   -1.00000 
    3    -0.11111   -0.25000   -1.00000    4.00000 
	
template<typename REAL >
void vandermonde ( DenseMatrix< REAL > &  A,
const Vector< REAL >  x 
) [related]


Function: make a vandermonde matrix

    template<typename REAL>
    inline void vandermonde (DenseMatrix<REAL> &A, const Vector<REAL> x)
Parameters:
[in]Areference to a DenseMatrix that shall be filled with entries
[in]xconstant reference to a Vector

Example:

    hdnum::Vector<double> x(4);
    fill(x,2.0,1.0);
    hdnum::DenseMatrix<double> A(4,4);
    vandermonde(A,x);

    A.scientific(false); // fixed point representation for all DenseMatrix objects
    A.width(10);
    A.precision(5);

    x.scientific(false); // fixed point representation for all Vector objects
    x.width(10);
    x.precision(5);

    std::cout << "x=" << x << std::endl;
    std::cout << "A=" << A << std::endl;

Output:

    x=
    [ 0]   2.00000
    [ 1]   3.00000
    [ 2]   4.00000
    [ 3]   5.00000

    A=
    0          1          2          3 
    0     1.00000    2.00000    4.00000    8.00000 
    1     1.00000    3.00000    9.00000   27.00000 
    2     1.00000    4.00000   16.00000   64.00000 
    3     1.00000    5.00000   25.00000  125.00000 

	

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