tsv.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 #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     // ================================================================= Linear Solver
00039 
00040     cout << "\n============================================== Linear Solver\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> Y(5,"-1 -1  1 0 2");
00044 
00045     cout << "A = \n" << A << endl;
00046     cout << "Y = \n" << Y << endl;
00047     
00048     if (Gesv(A,Y)==0)
00049     {
00050         cout << "Y := inv(A)*Y\n" << Y << endl;
00051         cout << "matrix A after solver = \n" << A << endl;
00052     }
00053     else
00054         cout << "ERROR: Impossible to solve [A]{X} = {Y} !\n";
00055 
00056     // =================================================== Linear Solver (Tridiagonal)
00057     
00058     cout << "\n================================== Linear Solver (Tridiagonal)\n";
00059 
00060     /*         [M]            {W}     {N}
00061      *  / 2 -1  0  0  0 \   / w0 \   / 1 \
00062      * | -1  2 -1  0  0 |   | w1 |   | 2 |
00063      * |  0 -2  3 -1  0 | * | w2 | = | 3 |.
00064      * |  0  0 -1  3 -2 |   | w3 |   | 2 |
00065      * \  0  0  0 -1  1 /   \ w4 /   \ 1 /
00066      *              \  \  \  
00067      *               L  D  U
00068     */
00069     
00070     Vector<REAL> L(4,"-1 -2 -1 -1");
00071     Vector<REAL> D(5,"2 2 3 3 1");
00072     Vector<REAL> U(4,"-1 -1 -1 -2");
00073     Vector<REAL> N(5,"1 2 3 2 1");
00074     
00075     cout << "L = \n" << L << endl;
00076     cout << "D = \n" << D << endl;
00077     cout << "U = \n" << U << endl;
00078     cout << "N = \n" << N << endl;
00079     
00080     Gtsv(L,D,U,N);
00081     cout << "N := W = inv(M)*N = \n" << N << endl;
00082     
00083 
00084     return 0;
00085 }
00086 catch (Exception * e) //{{{ 
00087 {
00088     e->Cout();
00089     if (e->IsFatal()) {delete e; exit(1);}
00090     delete e;
00091 }
00092 catch (char const * m)
00093 {
00094     std::cout << "Fatal: " << m << std::endl;
00095     exit (1);
00096 }
00097 catch (...)
00098 {
00099     std::cout << "Some exception (...) ocurred\n";
00100 } //}}} 
00101 
00102 // vim:fdm=marker

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