Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# matrices.h

    00001 #ifndef MATRICES_H
    00002 #define MATRICES_H
    00003
    00004 #include <vector>
    00005
    00006 class lower_triangular_matrix {
    00007
    00008     unsigned n;
    00009     std::vector<double> data;
    00010
    00011     public:
    00012
    00013     lower_triangular_matrix(unsigned n_ = 0) : n(n_), data(n * (n+1) / 2) {};
    00014
    00015     void resize(unsigned n_) {
    00016         n = n_;
    00017         data.resize(n*(n+1)/2);
    00018     }
    00019
    00020     std::vector<double>::iterator operator[](unsigned i) { return data.begin() + i * (i+1) / 2; }
    00021     std::vector<double>::const_iterator operator[](unsigned i) const { return data.begin() + i*(i+1)/2; }
    00022 };
    00023
    00024 class square_matrix {
    00025     unsigned n;
    00026     std::vector<double> data;
    00027
    00028     public:
    00029
    00030     square_matrix(unsigned n_ = 0) : n(n_), data(n * n) {};
    00031
    00032     void resize(unsigned n_) {
    00033         n = n_;
    00034         data.resize(n*n);
    00035     }
    00036
    00037     std::vector<double>::iterator operator[](unsigned i) { return data.begin() + i * n; }
    00038     std::vector<double>::const_iterator operator[](unsigned i) const { return data.begin() + i*n; }
    00039 };
    00040
    00041 #endif
    00042