/*This is the file testmatrix.C.  It is designed to show the basic features of
the Matrix class that has been defined in Matrix.h.  The functions are
basically just matrix arithmetic and are fairly straight forward.  As stated in
previous comments there is a difference with vector*matrix and matrix*vector.
The first case takes the vector to be a row vector and the latter assumes that
it is a column vector.  To compile this file type g++ testmatrix.C at the
prompt.*/

#include <iostream.h>
#include <iomanip.h>
#include "Matrix.h"

void main()
{
    try{
    Matrix<double> mat(5,5);//makes a 5x5 matrix
        mat(0,0)=2.0; //intialize each element to some number
        mat(0,1)=1.7;
        mat(0,2)=3.5;
        mat(0,3)=-2.0;
        mat(0,4)=1.6;
        mat(1,0)=1.7;
        mat(1,1)=3.0;
        mat(1,2)=-3.9;
        mat(1,3)=4.0;
        mat(1,4)=1.8;
        mat(2,0)=-3.0;
        mat(2,1)=-3.9;
        mat(2,2)=4.0;
        mat(2,3)=2.5;
        mat(2,4)=1.0;
        mat(3,0)=-1.0;
        mat(3,1)=2.8;
        mat(3,2)=1.5;
        mat(3,3)=-1.0;
        mat(3,4)=1.2;
        mat(4,0)=1.8,
        mat(4,1)=1.8;
        mat(4,2)=6.0;
        mat(4,3)=1.2;
        mat(4,4)=0.5;
        cout<<"Matrix 1 = "<<endl;
        cout<<mat; //print out the above matrix
        Matrix<double> mat2=2.8+mat;
        cout <<endl<<"mat2 = 2.8 + mat::Matrix 2 = "<<endl ;
        cout<<mat2;
        Matrix<double> mat3 = mat2 + mat;
        cout <<endl<<"mat3 = mat2 + mat1::Matrix 3 = "<<endl;
        cout<<mat3;
        Matrix<double> mat4 = mat3.transpose(); //will find the transpose
        cout <<endl<<"mat4 = transpose(mat3)::Matrix 4 = "<<endl;
        cout<<mat4;
        Matrix<double> mat5 = mat4 * mat3 +2.6;
        cout <<endl<<"mat5 = mat4*mat3+2.6::Matrix 5 =  "<<endl;
        cout<<mat5;
        cout<<endl<<"showing the previous matrices are unchnaged"<<endl;
        cout<<"Matrix 1 = "<<endl;
        cout<<mat;
        mat2-=mat5;
        cout <<endl<<"mat2 -= mat5::Matrix 2 = "<<endl ;
        cout<<mat2;
        Matrix<double> mat6 = (2.5*mat - mat3)+3.0 ;
        cout <<endl<<"mat6 = (2.5*mat - mat3)+3.0::Matrix 6 = "<<endl ;
        cout << mat6;
        cout <<endl<<"Number of elements in mat 6 = "<<NumElts(mat6)<<endl;
        cout<<endl<<"mat 7 = 4.0/mat::Matrix 7 = "<<endl;
        Matrix<double> mat7= 4.0/mat;
        cout<<mat7;
        cout<<endl<<"mat *= mat7::Matrix 1 = "<<endl;
        mat *= mat7;
        cout<<mat;
        cout<<endl<<"We want to solve the following set of equations:"<<endl;
        cout<<"       2x + 4y +  z =  -4.75"<<endl;
        cout<<"      -3x + 2y + 4z =  -7.50"<<endl;
        cout<<"        x - 2y + 2z =   6.00"<<endl;
        cout<<endl<<"We define linmat = "<<endl;
        Matrix<double> linmat(3,3);
        linmat(0,0) = 2.0;
        linmat(0,1) = 4.0;
        linmat(0,2) = 1.0;
        linmat(1,0) = -3.0;
        linmat(1,1) = 2.0;
        linmat(1,2) = 4.0;
        linmat(2,0) = 1.0;
        linmat(2,1) = -2.0;
        linmat(2,2) = 2.0;
        cout <<linmat;
        cout <<endl<<"And we define linvec = "<<endl;
        Vector<double> linvec(3);
        linvec(0) = -4.75;
        linvec(1) = -7.50;
        linvec(2) = 6.00;
        cout << linvec;
        cout<<endl<<"Then the soltion vector is :"<<endl;
        Vector<double> sol = inverse(linmat) * linvec;
        cout << sol;

    }
    catch (Exception& x){
        x.display(cerr);
    }
}
		 
