Dense Matrices

In that page, methods and functions related to dense matrices are detailed.

Basic declaration :

Classes :

Matrix<T,Prop,RowMajor>
Matrix<T,Prop,RowSymPacked>
Matrix<T,Prop,RowHermPacked>
Matrix<T,Prop,RowUpTriangPacked>
Matrix<T,Prop,RowLoTriangPacked>

Example :

  
// dense matrix of doubles
Matrix<double> A;

// dense symmetric matrix
Matrix<float, Symmetric, RowSymPacked> B;

// dense hermitian matrix
Matrix<double, General, RowHermPacked> > C;

// dense lower triangular matrix
Matrix<double, General, RowLoTriangPacked> > D;

// dense upper triangular matrix
Matrix<double, General, RowUpTriangPacked> > E;

Methods :

Matrix constructors
Matrix operators
GetM returns the number of rows in the matrix
GetN returns the number of columns in the matrix
GetSize returns the number of elements in the matrix
GetDataSize returns the number of elements effectively stored
GetData returns a pointer to the array containing the values
GetDataConst returns a pointer to the array containing the values
GetDataVoid returns a pointer to the array containing the values
GetDataConstVoid returns a pointer to the array containing the values
Clear removes all elements of the matrix
Reallocate changes the size of matrix (does not keep previous elements)
Resize changes the size of matrix (keeps previous elements)
SetData sets the pointer to the array containing the values
Nullify clears the matrix without releasing memory
Val access to a matrix element
Copy copies a matrix
Zero sets all elements to zero
SetIdentity sets matrix to identity matrix
Fill sets all elements to a given value
FillRand fills randomly the matrix
Print displays the matrix
Write writes the matrix in binary format
Read reads the matrix in binary format
WriteText writes the matrix in text format
ReadText reads the matrix in text format

Functions :

Mlt multiplication by a scalar or matrix-vector product
MltAdd performs a matrix-vector or matrix-matrix product
Add adds two matrices
Copy copies a matrix into another one
Rank1Update Adds a contribution X.Y' to a matrix
Rank2Update Adds a contribution X.Y' + Y.X' to a symmetric matrix
Solve solves a triangular system
Transpose replaces a matrix by its transpose
TransposeConj replaces a matrix by its conjugate transpose
MaxAbs returns highest absolute value of A
Norm1 returns 1-norm of A
NormInf returns infinity-norm of A
GetRow returns a matrix row
SetRow changes a matrix row
GetCol returns a matrix column
SetCol changes a matrix column
GetLU performs a LU (or LDL^t) factorization
SolveLU solve linear system by using LU factorization
RefineSolutionLU improves solution computed by SolveLU
ReciprocalConditionNumber computes the inverse of matrix condition number
GetScalingFactors computes row and column scalings to equilibrate a matrix
GetInverse computes the matrix inverse
GetQR QR factorization of matrix
GetLQ LQ factorization of matrix
GetQ_FromQR Forms explicitely Q from QR factorization
MltQ_FromQR multiplies vector by Q
SolveQR solves least-square problems by using QR factorization
SolveLQ solves least-square problems by using LQ factorization
GetEigenvalues computes eigenvalues
GetEigenvaluesEigenvectors computes eigenvalues and eigenvectors
GetSVD performs singular value decomposition (SVD)

Matrix constructors

Syntax :

  Matrix();
  Matrix(int, int );

Example :

  
// default constructor -> empty matrix
Matrix<int> V;
cout << "Number of elements "<< V.GetSize() << endl; // should return 0 
// then you can use Reallocate to set the number of rows and columns
V.Reallocate(3, 2);
V.Fill();

// we construct matrix with 4 rows and 3 columns
Matrix<double> W(4, 3);
// W is not initialized, you have to fill it
W.Fill(1.0);

Related topics :

Reallocate
Fill

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Matrix operators

Syntax :

  const T& operator (int i, int j) const;
  T& operator (int i, int j);
  T& operator [int i];
  const T& operator [int i] const;
  Matrix& operator =(const Matrix& )
  Vector& operator =(const T0& alpha)
  Vector& operator *=(const T0& alpha)

The operator [] should not be used in normal use. The operator () can't be used to modify values of matrix for specific storages, e.g. RowSym, RowHerm, RowUpTriang.

Example :

  
Matrix<double> V(3, 3);
// use of operator () to modify matrix
V(0, 0) = 2.0;
V(1, 0) = V(0, 0) + 1.0;

// operator [] should be used with caution
V[3] = V[0] + 1.4;

Matrix<double> W;
// use of operator = to copy contents of vector V
W = V;

// set all elements to a given value
W = 1;

// multiplication by a scalar
Matrix<double> A(3, 2);
A.Fill();
A *= 1.5;

Related topics :

Copy
Val

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

GetM

Syntax :

  int GetM() const;

This method returns the number of rows

Example :

  
Matrix<float> V(3, 2);
// V.GetM() should return 3 
cout << "Number of rows of V " << V.GetM() << endl;

Location :

Class Matrix_Base
Matrix_Base.hxx
Matrix_Base.cxx

GetN

Syntax :

  int GetN() const;

This method returns the number of columns.

Example :

  
Matrix<float> V(3, 2);
// V.GetN() should return 2 
cout << "Number of rows of V " << V.GetM() << endl;

Location :

Class Matrix_Base
Matrix_Base.hxx
Matrix_Base.cxx

GetSize

Syntax :

  int GetSize() const;

This method returns the number of elements in the matrix

Example :

  
Matrix<float, Symmetric, RowSymPacked> V(3, 3);
// V.GetSize() should return 9
cout << "Number of elements of V " << V.GetSize() << endl;

Location :

Class Matrix_Base
Matrix_Base.hxx
Matrix_Base.cxx

GetDataSize

Syntax :

  int GetDataSize() const;

This method returns the number of elements effectively stored in the matrix. This is different from GetSize for some storages, e.g. RowSymPacked, RowHermPacked, RowUpTriangPacked.

Example :

  
Matrix<float, Symmetric, RowSymPacked> V(3, 3);
// V.GetDataSize() should return 6
cout << "Number of elements of V " << V.GetDataSize() << endl;

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

GetData, GetDataConst, GetDataVoid, GetDataConstVoid

Syntax :

  T* GetData() const;
  const T* GetDataConst() const;
  void* GetDataVoid() const;
  const void* GetDataConstVoid() const;

These methods are useful to retrieve the pointer to the values. In practice, you can use those methods in order to interface with C/fortran subroutines or to perform some low level operations. But in this last case, you have to be careful, because debugging operations will be more tedious.

Example :

  
Matrix<double> V(3, 4); V.Fill();
double* data = V.GetData();
// you can use data as a normal C array
// here the sum of elements is computed
double sum = 0;
for (int i = 0; i < V.GetDataSize(); i++)
  sum += data[i];

// if you want to call a fortran subroutine daxpy
Matrix<double> X(3, 3); 
double coef = 2.0;
int m = X.GetM();
int n = X.GetN();
daxpy_(&coef, &m, &n, X.GetData(),);

// for complex numbers, conversion to void* is needed :
Matrix<complex<double> > Xc(4, 4);
complex<double> beta(1,1);
zaxpy(reinterpret_cast<const void*>(beta), Xc.GetDataVoid());

Related topics :

SetData
Nullify

Location :

Class Matrix_Base
Matrix_Base.hxx
Matrix_Base.cxx

Clear

Syntax :

  void Clear();

This method removes all the elements of the matrix.

Example :

  
Matrix<double> A(3, 2);
A.Fill();
// clears matrix A
A.Clear();

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Reallocate

Syntax :

  void Reallocate(int, int);

This method changes the size of the matrix, but removes previous elements.

Example :

  
Matrix<long int> A(5, 4);
V.Fill();
// resizes matrix A
A.Reallocate(4, 3);
// you need to initialize all elements of A
A.Zero();

Related topics :

Resize

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Resize

Syntax :

  void Resize(int, int);

This method changes the size of the matrix, and keeps previous elements.

Example :

  
Matrix<long double> A(3,3);
A.Fill();
// resizes matrix A
A.Resize(4,4);
// you need to initialize new elements if there are new
for (int i = 0; i < 4; i++)
  A(4,i) = A(i,4) = 0;

Related topics :

Reallocate

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

SetData

Syntax :

  void SetData(int, int, T*);

This method sets the pointer to the array containing elements. This method should be used carefully, and generally in conjunction with method Nullify.

Example :

  
// for example, you can define a function with a pointer as argument
void f(int m, int n, double* data)
{
  // and sets this array into a Matrix instance
  Matrix<double> A;
  // m : number of rows, n : number of columns
  A.SetData(m, n, data);
  // then you use a C++ method
  double coef = Norm1(A);
  // you don't release memory, because data is used after the function
  A.Nullify();
}

Related topics :

GetData
Nullify

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Nullify

Syntax :

  void Nullify();

This method clears the matrix without releasing memory. This method should be used carefully, and generally in conjunction with method Nullify. You can look at the example shown in the explanation of method SetData.

Related topics :

SetData
GetData

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Copy

Syntax :

  void Copy(const Matrix&);

This method copies a matrix into the current matrix.

Example :

  
// copy of a matrix M
Matrix<double> M(3, 3), A;
M.FillRand();
A.Copy(M);
// this is equivalent to use operator =
A = M;

Related topics :

Matrix operators

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Val

Syntax :

  T& Val(int, int);
  const T& Val(int, int) const;

This method is similar to operator (), except that it always works, especially for storages like RowSym, RowHerm, RowUpTriang.

Example :

  
Matrix<double, General, RowUpTriang> A(3,3);
// operator () does not work to change the value
// A(0,0) = 1;  => Error during compilation
A.Val(0,0) = 2.0;  // Okay it works

Related topics :

Operators

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Zero

Syntax :

  void Zero();

This method fills memory of 0, is convenient for matrices made of doubles, integers, floats, but not for more complicated types. In that case, it is better to use the method Fill.

Example :

  
Matrix<double> V(5, 3);
// initialization
V.Fill();

Matrix<IVect> W(10, 2);
// W.Zero() is incorrect and would generate an error at the execution
// a good initialization is to use Fill
IVect zero(5); zero.Zero();
W.Fill(zero);

Related topics :

Fill

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

SetIdentity

Syntax :

  void SetIdentity();

This method sets all elements to 0, except on the diagonal set to 1. This forms the so-called identity matrix.

Example :

  
Matrix<double> V(5, 5);
// initialization
V.SetIdentity();

Related topics :

Fill

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Fill

Syntax :

  void Fill();
  template<class T0>
  void Fill(const T0& );

This method fills matrix with 0, 1, 2, etc or with a given value.

Example :

  
Matrix<int> A(2,2);
A.Fill();
// A should contain [0 1; 2 3]

A.Fill(2);
// A should contain [2 2; 2 2]

Related topics :

Zero

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

FillRand

Syntax :

  void FillRand();

This method fills the matrix with random values.

Example :

  
Matrix<double> A(5, 3);
A.FillRand();
// A should contain 15 random values

Related topics :

Fill

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Print

Syntax :

  void Print() const;
  void Print(int) const;
  void Print(int, int, int, int) const;

This method displays the matrix.

Example :

  
Matrix<string> A(2, 2);
A(0,0) = string("hello");
A(0,1) = string("world");
A(1,0) = string("you");
A(1,1) = string("welcome");
A.Print(); 
// should display :
// hello world
// you welcome

// you can also display a sub-matrix
A.Print(0, 0, 0, 1); 
// should display "hello world"

// A.Print(2); is equivalent to A.Print(0, 0, 2, 2);

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Write

Syntax :

  void Write(string) const;
  void Write(ofstream&) const;

This method writes the matrix on a file/stream in binary format. The file will contain the number of rows, columns, then the list of elements.

Example :

  
Matrix<double> A(2, 2); 
// you can write directly in a file
A.Fill();
A.Write("matrix.dat");

// or open a stream with other datas
ofstream file_out("matrix.dat");
int my_info = 3;
file_out.write(reinterpret_cast<char*>(>my_info), sizeof(int));
A.Write(file_out);
file_out.close();

Related topics :

Read
WriteText
ReadText

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

Read

Syntax :

  void Read(string);
  void Read(ifstream&);

This method sets the matrix from a file/stream in binary format. The file contains the number of rows, columns, then the list of elements.

Example :

  
Matrix<double> V(3, 4); 
// you can read directly on a file
V.Read("matrix.dat");

// or read from a stream
ifstream file_in("matrix.dat");
int my_info;
file_in.read(reinterpret_cast<char*<(>my_info), sizeof(int));
V.Read(file_in);
file_in.close();

Related topics :

Write
WriteText
ReadText

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

WriteText

Syntax :

  void WriteText(string) const;
  void WriteText(ofstream&) const;

This method writes the matrix on a file/stream in text format. The file will contain the list of elements.

Example :

  
Matrix<double> V(2); 
// you can write directly in a file
V.Fill();
V.WriteText("matrix.dat");

// or open a stream with other datas
ofstream file_out("matrix.dat");
int my_info = 3;
file_out << my_info << '\n';
V.WriteText(file_out);
file_out.close();

Related topics :

Write
Read
ReadText

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx

ReadText

Syntax :

  void ReadText(string);
  void ReadText(ifstream&);

This method sets the matrix from a file/stream in text format. The file contains the list of elements.

Example :

  
Matrix<double> V; 
// you can read directly on a file
V.ReadText("matrix.dat");

// or read from a stream
ifstream file_in("matrix.dat");
int my_info;
file_in >> my_info;
V.ReadText(file_in);
file_in.close();

Related topics :

Write
Read
WriteText

Location :

Class Matrix_Pointers
Class Matrix_Symmetric
Class Matrix_SymPacked
Class Matrix_Hermitian
Class Matrix_HermPacked
Class Matrix_Triangular
Class Matrix_TriangPacked
Matrix_Pointers.hxx Matrix_Pointers.cxx
Matrix_Symmetric.hxx Matrix_Symmetric.cxx
Matrix_SymPacked.hxx Matrix_SymPacked.cxx
Matrix_Hermitian.hxx Matrix_Hermitian.cxx
Matrix_HermPacked.hxx Matrix_HermPacked.cxx
Matrix_Triangular.hxx Matrix_Triangular.cxx
Matrix_TriangPacked.hxx Matrix_TriangPacked.cxx