00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 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 00024 /** \file givens_base.h 00025 \brief File for Givens rotations 00026 */ 00027 00028 #ifdef DOXYGENP 00029 namespace o2scl_linalg { 00030 #endif 00031 00032 /// Desc 00033 template<class mat1_t, class mat2_t> 00034 void apply_givens_qr(size_t M, size_t N, mat1_t &Q, mat2_t &R, 00035 size_t i, size_t j, double c, double s) { 00036 00037 for(size_t k=0;k<M;k++) { 00038 double qki=O2SCL_IX2(Q,k,i); 00039 double qkj=O2SCL_IX2(Q,k,j); 00040 O2SCL_IX2(Q,k,i)=qki*c-qkj*s; 00041 O2SCL_IX2(Q,k,j)=qki*s+qkj*c; 00042 } 00043 for(size_t k=GSL_MIN(i,j);k<N;k++) { 00044 double rik=O2SCL_IX2(R,i,k); 00045 double rjk=O2SCL_IX2(R,j,k); 00046 O2SCL_IX2(R,i,k)=c*rik-s*rjk; 00047 O2SCL_IX2(R,j,k)=s*rik+c*rjk; 00048 } 00049 00050 return; 00051 } 00052 00053 /// Desc 00054 template<class mat1_t, class mat2_t> 00055 void apply_givens_lq(size_t M, size_t N, mat1_t &Q, mat2_t &L, 00056 size_t i, size_t j, double c, double s) { 00057 00058 for(size_t k=0;k<M;k++) { 00059 double qik=O2SCL_IX2(Q,i,k); 00060 double qjk=O2SCL_IX2(Q,j,k); 00061 O2SCL_IX2(Q,i,k)=qik*c-qjk*s; 00062 O2SCL_IX2(Q,j,k)=qik*s+qjk*c; 00063 } 00064 for(size_t k=GSL_MIN(i,j);k<N;k++) { 00065 double lki=O2SCL_IX2(L,k,i); 00066 double lkj=O2SCL_IX2(L,k,j); 00067 O2SCL_IX2(L,k,i)=c*lki-s*lkj; 00068 O2SCL_IX2(L,k,j)=s*lki+c*lkj; 00069 } 00070 00071 return; 00072 } 00073 00074 /// Desc 00075 template<class vec_t> 00076 void apply_givens_vec(vec_t &v, size_t i, size_t j, 00077 double c, double s) { 00078 double vi=O2SCL_IX(v,i); 00079 double vj=O2SCL_IX(v,j); 00080 O2SCL_IX(v,i)=c*vi-s*vj; 00081 O2SCL_IX(v,j)=s*vi+c*vj; 00082 return; 00083 } 00084 00085 #ifdef DOXYGENP 00086 } 00087 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page