next up previous contents
Next: 1.5.2 Compilation Up: 1.5 A Quick Look Previous: 1.5 A Quick Look   Contents

1.5.1 Example Code

#include <cstdlib>
#include <iostream>
#include "EMatrix.h"

using namespace std;
using namespace ematrix;

// For g++, compile with: -ansi -pedantic -Wall -D_HAVE_LAPACK 
// For Linux, link with: -llapack -lg2c
// N.B., If you don't have Lapack installed, don't worry about the link
//       options and don't include the -D_HAVE_LAPACK compile flag.

int main(void) {
  // Declare and set to random values where the template declaration
  // follows Matrix< type, rows, cols >
  Matrix<double,3,3> A; A.rand();
  Matrix<double,3,1> B; B.rand();
  Matrix<double,3,1> C; C.rand();
  Matrix<double,3,3> D; D.rand();
  if(A(2,3) != A[1][2]) {
    cerr << "There is foul play asunder!!" << endl;

  // copy constructor and binary addition operator
  Matrix<double,3,3> E = A+D;

  // stream operator, scalar and matrix multiplication, matrix transpose
  cout << trans(B+B)*E*C*5.0;
  // stream operator, scalar multiplication, matrix inverse
  // The inverse routine is provide through and interface to Lapack.
  cout << 0.5*inv(A) << endl;

Andrew Douglas 2005-03-15