STK++ 1.0
STK_Givens.h
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 /*     Copyright (C) 2004-2007  Serge Iovleff
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as
00006     published by the Free Software Foundation; either version 2 of the
00007     License, or (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this program; if not, write to the
00016     Free Software Foundation, Inc.,
00017     59 Temple Place,
00018     Suite 330,
00019     Boston, MA 02111-1307
00020     USA
00021 
00022     Contact : Serge.Iovleff@stkpp.org
00023 */
00024 
00025 /*
00026  * Project:  Algebra
00027  * Purpose:  Define Givens rotation methods for Algebra classes.
00028  * Author:   Serge Iovleff, serge.iovleff@stkpp.org
00029  *
00030  **/
00031 
00037 #ifndef STK_GIVENS_H
00038 #define STK_GIVENS_H
00039 
00040 #include "../../STKernel/include/STK_Real.h"
00041 #include "../../Sdk/include/STK_ITContainer2D.h"
00042 
00043 namespace STK
00044 {
00074 Real compGivens( Real const& y
00075                , Real const& z
00076                , Real& cosinus
00077                , Real& sinus
00078                );
00079 
00096 template < class TContainer2D>
00097 void rightGivens( ITContainer2D< Real, TContainer2D>& M
00098                 , Integer const& col1
00099                 , Integer const& col2
00100                 , Real const& cosinus
00101                 , Real const& sinus
00102                 )
00103 {
00104   const Integer first = M.firstRow(), last = M.lastRow();
00105   // Apply givens rotation
00106   for (Integer i = first; i <=last; i++)
00107   {
00108     const Real aux1 = M(i, col1), aux2 = M(i, col2);
00109     M(i, col1) = cosinus * aux1 + sinus * aux2;
00110     M(i, col2) = cosinus * aux2 - sinus * aux1;
00111   }
00112 }
00113 
00130 template < class TContainer2D>
00131 void leftGivens( ITContainer2D< Real, TContainer2D>& M
00132                , Integer const& row1
00133                , Integer const& row2
00134                , Real const& cosinus
00135                , Real const& sinus
00136                )
00137 {
00138   const Integer first = M.firstCol(), last = M.lastCol();
00139   // apply left Givens rotation
00140   for (Integer j = first; j<= last; j++)
00141   {
00142     const Real aux1 = M(row1, j), aux2 = M(row2, j);
00143     M(row1, j) = cosinus * aux1 + sinus * aux2;
00144     M(row2, j) = cosinus * aux2 - sinus * aux1;
00145   }
00146 }
00147 
00148 } // namespace STK
00149 
00150 #endif /*STK_GIVENS_H*/