nbl
10-25-2009, 06:25 AM
I would suggest to add an output algorithm for matrices and vectors to the file nr3.h.
const int os_precision_m = 7;
const int os_width_m = 5;
std::ostream& operator<<(std::ostream &os, const MatDoub &m){
os << std::setprecision(os_precision_m);
for (int i=0;i<m.nrows();i++){
for (int j=0;j<m.ncols();j++){
os << std::setw(os_width_m) << m[i][j];
}
std::cout << std::endl;
}
return os;
}
Than you can write a matrix to standard output with
#include "nr3.h"
int main(){
MatDoub a(2,2);
a[0][0] = 1; a[0][1] = -1;
a[1][0] = 0; a[1][1] = 2;
cout << "a" << endl << a << endl;
}
What do you think about that idea?
const int os_precision_m = 7;
const int os_width_m = 5;
std::ostream& operator<<(std::ostream &os, const MatDoub &m){
os << std::setprecision(os_precision_m);
for (int i=0;i<m.nrows();i++){
for (int j=0;j<m.ncols();j++){
os << std::setw(os_width_m) << m[i][j];
}
std::cout << std::endl;
}
return os;
}
Than you can write a matrix to standard output with
#include "nr3.h"
int main(){
MatDoub a(2,2);
a[0][0] = 1; a[0][1] = -1;
a[1][0] = 0; a[1][1] = 2;
cout << "a" << endl << a << endl;
}
What do you think about that idea?