function [a,c,s]=rotg(a,b) % Input: a,b % Output: a,c,s % Function rotg.m applies Givens rotation matrix [c s;-s c] to vector [a;b] % |a~| | c s| |a| % | |<--| | | | % |0 | |-s c| |b| % where a~ modified top element in vector and c, s elements of Given matrix. % Used with a version of GMRES (gmres.m) organized as suggested by % R.J. Hanson and D.R. Kincaid,"Notes on GMRES Algorithm Organization", % Technical Report TR-05-05, March 2005, % Computer Sciences Department, University of Texas at Austin. % Date = 5 March 2005. t = b; if(abs(a) > abs(b)) t = a; end scale = abs(a)+abs(b); if(scale <= 0) c=1; s=0; return end r=scale*sqrt((a/scale)^2 + (b/scale)^2); if(t < 0) r=-r; end c = a/r; s = b/r; a=r; end