# Dense matrices

## Introduction

Dense matrices are two-dimensional arrays in which all the coefficients are stored (even if they are zero). They provide classical arithmetic operations such as addition, subtraction, multiplication by scalars, vectors, matrices, ...

```template<class C, class R= linalg::rep2d<C> >   struct MatrDse;
```

The class `MatrDse` is parameterised by

• the type `C` of the coefficients,
• the internal representation `R`. The default value is `linalg::rep2d<C>`.

## Containers

Here are containers, which can be used for th einterneal representation `R`:

• `linalg::rep2d<C>`: this is the default container, in which the matrix are stored by columns , in an array of coefficients.
• `lapack::rep2d<C>`: for the allows use of the routines of the Lapack library.

## Example

```#include <synaps/arithm/gmp.h>
#include <synaps/arithm/double.h>
#include <synaps/linalg/MatrDse.h>       // General header file for linear algeb
#include <synaps/base/io/maple.h> // For output in maple format.

typedef VectDse<double> vector_t;
// Vector definition based on array1d container, with double coefficients.
typedef MatrDse<double> matrix_t;

// In order to use a matrix definition based on lapack container,
// one should use the following instructions
//    typedef MatrDse<double, lapack::rep2d<double> > matrix_t;
// This will allow us to use the routines of the lapack library.

template<class op, class X, class Y>
void print_proto()
{
typedef binary_operator_prototype<op,X,Y> proto;
print<proto>(std::cout);
std::cout << std::endl;
std::cout << "\t";
print<typename proto::F>(std::cout); std::cout << std::endl;
std::cout << "\t";
print<typename proto::U>(std::cout); std::cout << std::endl;
std::cout << "\t";
print<typename proto::V>(std::cout); std::cout << std::endl;
std::cout << std::endl;
};
int main(int argc, char** argv)
{

using std::cout;
using std::endl;
double v[]={1,2,1,1,3,4,2,2,5,5,5,5,-2, 1,2,3,1, -2.8,-2.4,1,.2,5.8};
MatrDse<double> A(4,4,v,ByRow());
MatrDse<ZZ>     B(4,4,"1 2 1 1 3 4 2 2 5 5 5 5 -2  1 2 3 1 .2 5.8", ByCol());
MatrDse<QQ>     C;

cout<<"A="<<A<<", B="<<B<<endl;
// Arithmetic operations    matrix_t C; C = A+B; cout << C << endl;
C=A-B;   cout<<C<<endl;
C=A*B;   cout<<C<<endl;
C = A*B*A; cout<<C<<endl;
C = 2*A;  cout<<C<<endl;

//   // Construction of a Vector from to iterators.
vector_t V(v+1,v+5);  cout<<V<<endl;
vector_t W(A*V);     cout <<W<< endl;

std::cout << std::endl;
//Extractions of sub matrices of vectors.
// print_proto<linalg::_col_,MatrDse<double>, int  >();
W = col(A,1);       cout<<"Col(A,1) = "<<W<<endl;
W = row(A,2);       cout<<"Row(A,2) = "<<W<<endl;

B = A(Range(1,3),Range(1,3));  cout<<"A(1..3,1..3) = "<<B <<endl;

B = row(A,Range(1,2));         cout<<B<<endl;
B = col(A,Range(1,2));         cout<<B<<endl;

//Addition of the row 2 times 1.5 into row 1

//   // Output to the maple format.
cmaple<<A<<endl;

return 0;
}

```

## Implementation

`synaps/linalg/MatrDse.h`