00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define _NMBFMT std::setw(12) <<
00023
00024 #include <iostream>
00025 #include <cmath>
00026 #include <iomanip>
00027
00028 #include "linalg/lawrap.h"
00029 #include "linalg/matrix.h"
00030 #include "linalg/vector.h"
00031 #include "util/exception.h"
00032
00033 using namespace std;
00034 using namespace LinAlg;
00035
00036 int main() try
00037 {
00038
00039
00040 cout << "\n============================================== Matrix x Vector\n";
00041
00042 Matrix<REAL> A(5,5,"3 1 3 1 8 1 5 9 -2 4 2 6 5 0 -7 1 2 2 3 1 1 2 3 1 -1");
00043 Vector<REAL> X(5,"-1 -1 1 0 2");
00044 Vector<REAL> Y(5); Y.SetValues(1);
00045
00046 cout << "A = \n" << A << endl;
00047 cout << "X = \n" << X << endl;
00048 cout << "Y = \n" << Y << endl;
00049
00050 double a = 1.1;
00051 double b = -8.0;
00052 Gemv(a,A,X,b,Y);
00053 cout << "Y := " << a << "*A*X + " << b << "*Y = \n" << Y << endl;
00054
00055
00056
00057 cout << "\n============================================== Matrix x Matrix\n";
00058
00059 Matrix<REAL> B(5,5,"4 1 2 1 1 1 5 9 0 3 2 4 2 -1 2 0 0 1 -1 1 2 0 0 -1 1");
00060 Matrix<REAL> C(5,5,"0 1 -1 0 1 1 2 3 1 1 -1 0 1 1 1 2 -1 0 1 1 -2 -1 -1 -1 0");
00061 Matrix<REAL> E(5,5); E.SetValues(1);
00062
00063 cout << "B = \n" << B << endl;
00064 cout << "C = \n" << C << endl;
00065 cout << "E = \n" << E << endl;
00066
00067 a = -2.0;
00068 b = 3.0;
00069 Gemm(a,B,C,b,E);
00070 cout << "E := " << a << "*B*C + " << b << "*E = \n" << E << endl;
00071
00072
00073
00074 cout << "\n========================================== Matrix^(T) x Matrix\n";
00075
00076 E.SetValues(1);
00077
00078 Gemtm(a,B,C,b,E);
00079 cout << "E := " << a << "*(B^T)*C + " << b << "*E = \n" << E << endl;
00080
00081
00082
00083 cout << "\n========================================== Matrix x Matrix^(T)\n";
00084
00085 E.SetValues(1);
00086
00087 Gemmt(a,B,C,b,E);
00088 cout << "E := " << a << "*B*(C^T) + " << b << "*E = \n" << E << endl;
00089
00090
00091
00092 cout << "\n====================================== Matrix^(T) x Matrix^(T)\n";
00093
00094 E.SetValues(1);
00095
00096 Gemtmt(a,B,C,b,E);
00097 cout << "E := " << a << "*(B^T)*(C^T) + " << b << "*E = \n" << E << endl;
00098
00099
00100
00101 cout << "\n========================================== Vector x Vector^(T)\n";
00102
00103 Matrix<REAL> F(5,9); F.SetValues(0);
00104 Vector<REAL> Z(9,"4 3 2 1 0 -1 2 3 4");
00105 X.Reset("0 1 2 3 4");
00106
00107 cout << "F = \n" << F << endl;
00108 cout << "X = \n" << X << endl;
00109 cout << "Z = \n" << Z << endl;
00110
00111 Ger(1,X,Z,F);
00112 cout << "F := F + " << 1 << "*X*Z^T = \n" << F << endl;
00113
00114 return 0;
00115 }
00116 catch (Exception * e)
00117 {
00118 e->Cout();
00119 if (e->IsFatal()) {delete e; exit(1);}
00120 delete e;
00121 }
00122 catch (char const * m)
00123 {
00124 std::cout << "Fatal: " << m << std::endl;
00125 exit (1);
00126 }
00127 catch (...)
00128 {
00129 std::cout << "Some exception (...) ocurred\n";
00130 }
00131
00132