Object-oriented Scientific Computing Library: Version 0.910
givens_base.h
Go to the documentation of this file.
00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006-2012, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   O2scl is free software; you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation; either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   O2scl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00020   
00021   -------------------------------------------------------------------
00022 */
00023 /* linalg/givens.c
00024  * 
00025  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
00026  * 
00027  * This program is free software; you can redistribute it and/or modify
00028  * it under the terms of the GNU General Public License as published by
00029  * the Free Software Foundation; either version 3 of the License, or (at
00030  * your option) any later version.
00031  * 
00032  * This program is distributed in the hope that it will be useful, but
00033  * WITHOUT ANY WARRANTY; without even the implied warranty of
00034  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00035  * General Public License for more details.
00036  * 
00037  * You should have received a copy of the GNU General Public License
00038  * along with this program; if not, write to the Free Software
00039  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
00040  * 02110-1301, USA.
00041  */
00042 /** \file givens_base.h
00043     \brief File for Givens rotations
00044 
00045     \todo Make sure create_givens() in givens.h is documented.
00046 */
00047 
00048 #ifdef DOXYGENP
00049 namespace o2scl_linalg {
00050 #endif
00051 
00052   /** \brief Apply a rotation to matrices from the QR decomposition
00053 
00054       This performs \f$ Q \rightarrow Q G \f$ and 
00055       \f$ R \rightarrow G^{T} R \f$.
00056    */
00057   template<class mat1_t, class mat2_t>
00058     void apply_givens_qr(size_t M, size_t N, mat1_t &Q, mat2_t &R, 
00059                          size_t i, size_t j, double c, double s) {
00060 
00061     for(size_t k=0;k<M;k++) {
00062       double qki=O2SCL_IX2(Q,k,i);
00063       double qkj=O2SCL_IX2(Q,k,j);
00064       O2SCL_IX2(Q,k,i)=qki*c-qkj*s;
00065       O2SCL_IX2(Q,k,j)=qki*s+qkj*c;
00066     }
00067     for(size_t k=GSL_MIN(i,j);k<N;k++) {
00068       double rik=O2SCL_IX2(R,i,k);
00069       double rjk=O2SCL_IX2(R,j,k);
00070       O2SCL_IX2(R,i,k)=c*rik-s*rjk;
00071       O2SCL_IX2(R,j,k)=s*rik+c*rjk;
00072     }
00073 
00074     return;
00075   }
00076 
00077   /** \brief Apply a rotation to matrices from the LQ decomposition
00078 
00079       This performs \f$ Q \rightarrow Q G \f$ and 
00080       \f$ L \rightarrow L G^{T} \f$.
00081    */
00082   template<class mat1_t, class mat2_t>
00083     void apply_givens_lq(size_t M, size_t N, mat1_t &Q, mat2_t &L, 
00084                          size_t i, size_t j, double c, double s) {
00085 
00086     for(size_t k=0;k<M;k++) {
00087       double qik=O2SCL_IX2(Q,i,k);
00088       double qjk=O2SCL_IX2(Q,j,k);
00089       O2SCL_IX2(Q,i,k)=qik*c-qjk*s;
00090       O2SCL_IX2(Q,j,k)=qik*s+qjk*c;
00091     }
00092     for(size_t k=GSL_MIN(i,j);k<N;k++) {
00093       double lki=O2SCL_IX2(L,k,i);
00094       double lkj=O2SCL_IX2(L,k,j);
00095       O2SCL_IX2(L,k,i)=c*lki-s*lkj;
00096       O2SCL_IX2(L,k,j)=s*lki+c*lkj;
00097     }
00098 
00099     return;
00100   }
00101   
00102   /// Apply a rotation to a vector, \f$ v \rightarrow G^{T} v \f$
00103   template<class vec_t>
00104     void apply_givens_vec(vec_t &v, size_t i, size_t j,
00105                           double c, double s) {
00106     double vi=O2SCL_IX(v,i);
00107     double vj=O2SCL_IX(v,j);
00108     O2SCL_IX(v,i)=c*vi-s*vj;
00109     O2SCL_IX(v,j)=s*vi+c*vj;
00110     return;
00111   }
00112 
00113 #ifdef DOXYGENP
00114 }
00115 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.