00001 #include "..\common\matrix.h"
00002 #include "..\common\types.h"
00003 #include "..\common\utils.h"
00004 #include <iostream>
00005 #include <stdlib.h>
00006 #include <math.h>
00007 #include<valarray>
00008 using namespace std;
00009
00010
00016 bool mainmatrix(void){
00017 cout << "Test cholesky." << endl;
00018
00019 Matrix M2chol,M3cholTrans,M4recombChol;
00020 Matrix M1testChol= Matrix (0.0,3,3);
00021
00022 M1testChol.SetValue(0,0,5);
00023 M1testChol.SetValue(0,1,4);
00024 M1testChol.SetValue(0,2,1);
00025 M1testChol.SetValue(1,0,4);
00026 M1testChol.SetValue(1,1,10);
00027 M1testChol.SetValue(1,2,7);
00028 M1testChol.SetValue(2,0,1);
00029 M1testChol.SetValue(2,1,7);
00030 M1testChol.SetValue(2,2,25);
00031 cout << M1testChol << endl;
00032
00033 M2chol=M1testChol.CholeskyDecomposition();
00034 cout << M2chol << endl;
00035
00036 M3cholTrans=M2chol.GetTransposed();
00037 cout << M3cholTrans << endl;
00038
00039 M4recombChol=M2chol*M3cholTrans;
00040 cout << M4recombChol << endl;
00041
00043
00044 cout << "\nTest utils"<<endl;
00045
00046 Matrix M1= M1testChol;
00047 Matrix M2;
00048 Matrix M3= Matrix(0.0,3,1);
00049 Matrix M4;
00050
00051 cout << M1 << endl;
00052
00053 valarray<valarray<Real> > array=transformMatrixTo2Dvalarray(M1);
00054
00055 Natural col=(Natural)array.size();
00056 Natural row=(Natural)array[0].size();
00057 for(Natural i=0;i<row;i++){
00058 for(Natural j=0;j<col;j++)
00059 cout<<array[i][j]<< endl;
00060 cout<<"\n"<<endl;
00061 }
00062
00063 M2=transform2DvalarrayToMatrix(array);
00064 cout << M2 << endl;
00065
00066 M3.SetValue(0,0,5);
00067 M3.SetValue(1,0,4);
00068 M3.SetValue(2,0,1);
00069 cout << M3 << endl;
00070
00071 valarray<Real> array2=transformColumnMatrixTo1Dvalarray(M3);
00072 Natural size=(Natural)array.size();
00073 for(Natural i=0;i<size;i++)
00074 cout<<array2[i] <<endl;
00075
00076 M4=transform1DvalarrayToColumnMatrix (array2);
00077 cout << M4 << endl;
00078
00079 return false;
00080 }