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
     58
     59
     60
     61
     62
     63
     64
     65
     66

#include <flens/flens.cxx>
#include <iostream>

using namespace flens;
using namespace std;

int
main()
{
    typedef complex<double>             Complex;
    const Complex                       I(0,1);

    GeMatrix<FullStorage<Complex> >     A(44);
    DenseVector<Array<Complex> >        b(4);
    DenseVector<Array<int> >            piv(4);

///
/// Setup matrix $A$.  Note that `2+I` or `2*I` would not work.  That's because
/// the STL does not define the operation `int+complex<double>` or
/// `int*complex<double>`.
///
    A =   2,    3,  -I,    0,
         -6,   -5,   0, 2.+I,
       2.*I,   -5,   6,   -6,
          4, 6.*I,   2,   -3;

    b = 20,
       -33.*I,
       -43,
        49;

    cout << "A = " << A << endl;
    cout << "b = " << b << endl;

///
/// Compute the $LU$ factoriation of $A$.
///
    int info = lapack::trf(A, piv);

///
/// If `info` is not zero then the matrix was singular.  More precise, the
/// upper triangular matrix $U$ computed by `trf` is exactly singular.
///
    if (info!=0) {
        cerr << "A is singular" << endl;
        return info;
    }

///
///  Compute $A^{-1}$ from the $LU$ factorization of $A$.
///
    lapack::tri(A, piv);
    cout << "inv(A) = " << A << endl;

///
/// Compute $x = A^{-1}b$.
///
    DenseVector<Array<Complex> >        x;
    x = A*b;

    cout << "x = inv(A)*b = " << x << endl;

    return 0;
}