Matrices set precision
Mar 30, 2014 at 1:25am UTC
I wrote a code to perform a matrix operation but I need to set the precision to 3 decimal places for the results. I'm having trouble doing so because I'm not getting any different from if the set precision commands were not there. Any help?
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
#include <cstdlib>
#include <iostream>
#include <cmatrix>
#include <iomanip>
using namespace std;
typedef techsoft::matrix<int > iMatrix;
int main()
{
//Set Precision
cout.setf(ios::fixed);
cout.precision(3);
//Declare Matrices
int Bdata []={-2, 2,-1,5}, Cdata []={3, 2, -1, -2, 0, 2};
iMatrix B(2,2,Bdata);
iMatrix C(3,2,Cdata);
//Display
cout << "This program uses a matrix class from Techsoft." << endl;
cout << endl;
cout << "Matrix C" << endl;
cout << setw(2) << C << endl;
cout << endl;
cout << "Matrix B" << endl;
cout << B << endl;
cout << endl;
cout << "Matrix (CB)(C transpose)" << endl;
cout << setw(3) << (C*B)*~C << endl;
return 0;
}
Last edited on Mar 30, 2014 at 2:34am UTC
Topic archived. No new replies allowed.