1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
#include <iostream>
#include <flens/flens.cxx>

using namespace std;
using namespace flens;

typedef double   T;

int
main()
{
    typedef GbMatrix<BandStorage<T> >           Matrix;
    typedef DenseVector<Array<T> >              Vector;

    typedef Matrix::IndexType                   IndexType;
    typedef DenseVector<Array<IndexType> >      IndexVector;

    const IndexType n = 4;

///
/// The first two indices define the dimensions, the two last ones the
/// the number of sub- and superdiagonals.
///

    Matrix         Ab(n, n, 21);
    Vector         b(n), x(n);

    Ab.viewDiag(-2) =  23;
    Ab.viewDiag(-1) = -65, -4;
    Ab.viewDiag( 0) =  43,  5, -1;
    Ab.viewDiag( 1) =  12,  7;

    b = 20,
       -33,
       -43,
        49;

    cout << "Ab = " << Ab << endl;
    cout << "b  = " << b << endl;

    ///
    /// The function lower() creates a triangular banded matrix.
    /// We compute $x = A_{lower}^T b$.
    ///
    x = transpose(Ab.lower())*b;

    cout << "x = " << x << endl;

    ///
    /// And solve  $x = A_{lower}^T b$.
    ///
    blas::sv(Trans, Ab.lower(), x);

    cout << "b = " << x << endl;

    return 0;
}