teigen1.cpp

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #include <iostream>
00023 #include <cmath>
00024 #include <iomanip>
00025 
00026 #include "linalg/matrix.h"
00027 #include "linalg/vector.h"
00028 #include "linalg/lawrap.h"
00029 
00030 using namespace std;
00031 using namespace LinAlg;
00032 
00033 int main()
00034 {
00035     Matrix<REAL> A(4,4,"5 2 3 1   2 8 1 1   3 1 8 5   1 1 5 10");
00036     Vector<REAL> v(4);    // Eigenvalues
00037     Matrix<REAL> * P = new Matrix<REAL> [4];
00038     for (int i=0; i<4; ++i) P[i].Set(4,4); // Eigenprojectors
00039 
00040     cout << "A = \n" << A << endl;
00041 
00042     Syep(A,v,P);
00043     for (int i=0; i<4; ++i)
00044         cout << "P[" << i << "] =\n" << P[i] << endl;
00045 
00046     Matrix<REAL> Check(4,4);
00047     for (int i=0; i<4; ++i)
00048     for (int j=0; j<4; ++j)
00049         for (int k=0; k<4; ++k)
00050             Check(i,j) = Check(i,j) + v(k)*P[k](i,j);
00051     cout << "v0*P0 + v1*P1 + v2*P2 + v3*P3 =\n" << Check << endl;
00052 
00053     for (int i=0; i<4; ++i)
00054     {
00055         double trace=0.0;
00056         for (int j=0; j<4; ++j)
00057             trace += P[i](j,j);
00058         cout << "trace(P[" << i << "]) = " << trace << endl;
00059     }
00060     
00061     delete [] P;
00062 
00063     return 0;
00064 }

Generated on Wed Jan 24 15:56:26 2007 for MechSys by  doxygen 1.4.7