00001 #include<iostream>
00002 #include "GMatrix.h"
00003 #include "GVector.h"
00004 #include "GLinear_Homo_Eq.h"
00005 #include "util/GProgress_Bar.h"
00006
00007
00008 using namespace GMathLib;
00009 using namespace GMathLib::Util;
00010
00011 int main(){
00012 const int N = 7;
00013 double d1[N*N] = {
00014 2, 1, 6, 3, 7, 8, 9,
00015 4, 3, 8, 4, 1, 1, 2,
00016 3, 2, 2.3, 4, 1, 4, 0,
00017 2, 3, 4, 6, 7.1, 3, 2,
00018 1, 1, 1, 3, 1, 6, 7,
00019 2, 0, -1, 1, 2, 5, 3,
00020 4, -2, 2, 6, 5.6, 2, 1
00021 };
00022 double v1[N] = {4, 3, 8, 7, 3.2, 3, 8};
00023 double v2[N] = {0, 0, 0, 0, 0, 0, 0};
00024
00025
00026 GMatrix *matrix1 = new GMatrix(N, N, d1);
00027 matrix1->Object_Name("matrix1");
00028
00029 GVector *vec1 = new GVector(N, GVector::COLUMN_VECTOR, v1);
00030 vec1->Object_Name("vec1");
00031
00032 GMatrix matrix1l(N, N);
00033 matrix1l.Copy(*matrix1);
00034 matrix1->Object_Name("matrix1l");
00035
00036 GVector vec1l(N, GVector::COLUMN_VECTOR);
00037 vec1l.Copy(*vec1);
00038 vec1l.Object_Name("vec1l");
00039
00040 GVector *vec2 = new GVector(N, GVector::COLUMN_VECTOR, v2);
00041 vec2->Object_Name("vec2");
00042
00043
00044
00045 GLinear_Homo_Eq lse_gauss;
00046 GLinear_Homo_Eq lse_lu;
00047 int loopNum = 100;
00048
00049 GProgress_Bar bar1;
00050 bar1.Prepair(loopNum, "Gauss Ellimination loop");
00051
00052 for(int i=0; i < loopNum; i++){
00053 matrix1l.Copy(*matrix1); vec1l.Copy(*vec1);
00054 lse_gauss.S_Gauss_Partial_Pivot(matrix1l, vec1l, *vec2);
00055
00056 bar1.Update_Counter();
00057 }
00058
00059 vec2->Print();
00060
00061 GProgress_Bar bar2;
00062 bar2.Prepair(loopNum, "LU Method loop");
00063
00064 for(int i=0; i < loopNum; i++){
00065 matrix1l.Copy(*matrix1); vec1l.Copy(*vec1);
00066
00067 if(i==0){
00068 lse_lu.S_LU_Partial_Pivot(matrix1l, vec1l, *vec2);
00069 }else{
00070 lse_lu.S_LU_Partial_Pivot(matrix1l, vec1l, *vec2, false);
00071 }
00072
00073 bar2.Update_Counter();
00074 }
00075 vec2->Print();
00076
00077
00078 delete matrix1;
00079 delete vec1;
00080 delete vec2;
00081
00082 return 0;
00083 }