hermite.cpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  File:       hermite.cpp
00004 //  Created:    2005/10/18    23:24
00005 //
00006 //  Author: Andrey Somsikov
00007 */
00008 
00009 #include "config.hpp"
00010 
00011 #if !defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE) || \
00012     defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_hermite)
00013 
00014 #include "hermite.hpp"
00015 #include <iostream>
00016 
00017 namespace Arageli
00018 {
00019 
00020 template <class T>
00021 matrix<T> hermite_old (const matrix<T> &m)
00022 {
00023     typedef matrix<T> M;
00024     typedef typename M::value_type MV;
00025     typedef typename M::size_type size_type;
00026 
00027     M res(m);
00028 
00029     size_type i = 0, j = 0;
00030     while(i < res.nrows()-1 && j < res.ncols()-1)
00031     {
00032 /*
00033 output_aligned(std::cout, res, "|| ", " ||", "  ");
00034 std::cout << "\n";
00035 */
00036         // ensure that el(i,j)>0
00037         if (is_null(res.el(i, j)))
00038         {
00039             size_type k;
00040             // find non zero element in column j
00041             for (k = i+1; k < res.nrows(); k++)
00042                 if (!is_null(res.el(k, j)))
00043                     break;
00044             if (k == res.nrows())
00045             {
00046                 // skip column if not found
00047                 j++;
00048                 continue;
00049             }
00050             res.swap_rows(i, k);
00051 /*
00052             // ???
00053             if (res.el(i, j) < factory<MV>::null())
00054                 res.mult_row(i, factory<MV>::opposite_unit());
00055 */
00056         }
00057 
00058         // find pivot element
00059         size_type minValueIndex = i;
00060         bool isNonZero = false;
00061         for (size_type k = i+1; k < res.ncols(); k++)
00062         {
00063             if (!is_null(res.el(k, j)))
00064             {   
00065                 isNonZero = true;
00066                 if (res.el(k, j).degree() < res.el(minValueIndex, j).degree())
00067                     minValueIndex = k;
00068             }
00069         }
00070         if (!isNonZero)
00071         {
00072             // nothing to do with this element
00073             i++;
00074             j++;
00075             continue;
00076         }
00077         res.swap_rows(i, minValueIndex);
00078 /*
00079         if (res.el(i, j) < factory<MV>::null())
00080             res.mult_row(i, factory<MV>::opposite_unit());
00081 */
00082 
00083         for (size_type k = 0; k < i; k++)
00084             res.addmult_rows(k, i, factory<MV>::opposite_unit()*(res.el(k, j) / res.el(i, j)));
00085         for (size_type k = i+1; k < res.ncols(); k++)
00086             res.addmult_rows(k, i, factory<MV>::opposite_unit()*(res.el(k, j) / res.el(i, j)));
00087     }
00088 
00089     return res;
00090 }
00091 
00092 } // namespace Arageli
00093 
00094 #endif // #ifndef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE
00095 
00096 /* End of file hermite.cpp */

Generated on Thu Aug 31 17:38:06 2006 for Arageli by  doxygen 1.4.7