Givens rotation

Short description: Concept in numerical linear algebra

In numerical linear algebra, a Givens rotation is a rotation in the plane spanned by two coordinates axes. Givens rotations are named after Wallace Givens, who introduced them to numerical analysts in the 1950s while he was working at Argonne National Laboratory.

## Contents

* 1 As action on matrices
* 2 Matrix representation
* 3 Stable calculation
* 4 Triangularization
* 4.1 QR iteration variant
* 5 Complex matrices
* 6 In Clifford algebras
* 7 Dimension 3
* 7.1 Table of composed rotations
* 8 See also
* 9 Notes
* 10 Citations
* 11 References

## As action on matrices

A Givens rotation acting on a matrix from the left is a row operation, moving data between rows but always within the same column. Unlike the elementary operation of row-addition, a Givens rotation changes both of the rows addressed by it. To understand how it is a rotation, one may denote the elements of one target row by x1 through xn and the elements of the other target row by y1 through yn: [⋮⋮⋱⋮x1x2…xn⋮⋮⋱⋮y1y2…yn⋮⋮⋱⋮] Then the effect of a Givens rotation is to rotate each subvector (xk,yk) by the same angle. As with row-addition, algorithms often choose this angle so that one specific element becomes zero, and whatever happens in remaining columns is considered acceptable side-effects.

A Givens rotation acting on a matrix from the right is instead a column operation, moving data between two columns but always within the same row. As with action from the left, it rotates each subvector (xk,yk) by the same angle, but here these named elements occur in the matrix as […x1…y1……x2…y2…⋱⋮⋱⋮⋱…xn…yn…] Some algorithms, especially those concerned with preserving matrix similarity, apply Givens rotations as a conjugate action: both rotating by one angle between two rows, and rotating by the same angle between the corresponding columns. In this case the effect on the four elements affected by both rotations is more complicated; a Jacobi rotation is such a conjugate action to the end of zeroing the two off-diagonal elements among these four.

The main use of Givens rotations in numerical linear algebra is to transform vectors or matrices into a special form with zeros in certain coefficients. This effect can, for example, be employed for computing the QR decomposition of a matrix. One advantage over Householder transformations is that they can easily be parallelised, and another is that often for very sparse matrices they have a lower operation count.

## Matrix representation

A Givens rotation is represented by a matrix of the form

G(i,j,θ)=[1⋯0⋯0⋯0⋮⋱⋮⋮⋮0⋯c⋯−s⋯0⋮⋮⋱⋮⋮0⋯s⋯c⋯0⋮⋮⋮⋱⋮0⋯0⋯0⋯1],

where c = cos θ and s = sin θ appear at the intersections ith and jth rows and columns. That is, for fixed i > j, the non-zero elements of Givens matrix are given by:

gkk=1for k≠i,jgkk=cfor k=i,jgji=−gij=−s

The product G(i, j, θ)x represents a counterclockwise rotation of the vector x in the (i, j) plane of θ radians, hence the name Givens rotation.

## Stable calculation

When a Givens rotation matrix, G(i, j, θ), multiplies another matrix, A, from the left, G A, only rows i and j of A are affected. Thus we restrict attention to the following counterclockwise problem. Given a and b, find c = cos θ and s = sin θ such that

[c−ssc][ab]=[r0],

where r=a2+b2 is the length of the vector (a,b). Explicit calculation of θ is rarely necessary or desirable. Instead we directly seek c and s. An obvious solution would be

c<-a/rs<-−b/r.[1]

However, the computation for r may overflow or underflow. An alternative formulation avoiding this problem (Golub Van Loan) is implemented as the hypot function in many programming languages.

The following Fortran code is a minimalistic implementation of Givens rotation for real numbers. If the input values 'a' or 'b' are frequently zero, the code may be optimized to handle these cases as presented here.

subroutine givens_rotation(a, b, c, s, r)

real a, b, c, s, r
real h, d

if (b .ne. 0.0) then
h = hypot(a, b)
d = 1.0 / h
c = abs(a) * d
s = sign(d, a) * b
r = sign(1.0, a) * h
else
c = 1.0
s = 0.0
r = a
end if

return
end

Furthermore, as Edward Anderson discovered in improving LAPACK, a previously overlooked numerical consideration is continuity. To achieve this, we require r to be positive.[2] The following MATLAB/GNU Octave code illustrates the algorithm.

function [c, s, r] = givens_rotation(a, b)
if b == 0;
c = sign(a);
if (c == 0);
c = 1.0; % Unlike other languages, MatLab's sign function returns 0 on input 0.
end;
s = 0;
r = abs(a);
elseif a == 0;
c = 0;
s = -sign(b);
r = abs(b);
elseif abs(a) > abs(b);
t = b / a;
u = sign(a) * sqrt(1 + t * t);
c = 1 / u;
s = -c * t;
r = a * u;
else
t = a / b;
u = sign(b) * sqrt(1 + t * t);
s = -1 / u;
c = t / u;
r = b * u;
end
end

The IEEE 754 `copysign(x,y)` function, provides a safe and cheap way to copy the sign of `y` to `x`. If that is not available, |x|⋅sgn(y), using the abs and sgn functions, is an alternative as done above.

## Triangularization

Given the following 3×3 Matrix:

A1=[650514043],

two iterations of the Givens rotation (note that the Givens rotation algorithm used here differs slightly from above) yield an upper triangular matrix in order to compute the QR decomposition.

In order to form the desired matrix, zeroing elements (2,1) and (3,2) is required; element (2,1) is zeroed first, using a rotation matrix of:

G1=[c−s0sc0001].

The following matrix multiplication results:

G1A1=A2=[c−s0sc0001][650514043],

where

r=62+52≈7.8102c=6/r≈0.7682s=−5/r≈−0.6402.

Using these values for c and s and performing the matrix multiplication above yields A2:

A2≈[7.81024.48132.56070−2.43273.0729043]

Zeroing element (3,2) finishes off the process. Using the same idea as before, the rotation matrix is:

G2=[1000c−s0sc]

Afterwards, the following matrix multiplication is:

G2A2=A3≈[1000c−s0sc][7.81024.48132.56070−2.43273.0729043],

where

r≈(−2.4327)2+42≈4.6817c≈−2.4327/r≈−0.5196s≈−4/r≈−0.8544.

Using these values for c and s and performing the multiplications results in A3:

A3≈[7.81024.48132.560704.68170.966500−4.1843].

This new matrix A3 is the upper triangular matrix needed to perform an iteration of the QR decomposition. Q is now formed using the transpose of the rotation matrices in the following manner:

Q=G1TG2T.

Performing this matrix multiplication yields:

Q≈[0.76820.33270.54700.6402−0.3992−0.656400.8544−0.5196].

This completes two iterations of the Givens Rotation and calculating the QR decomposition can now be done.

### QR iteration variant

If performing the above calculations as a step in the QR algorithm for finding the eigenvalues of a matrix, then one next wants to compute the matrix RQ, but one should not do so by first multiplying G1T and G2T to form Q, instead rather by multiplying each GkT by RG1T…Gk−1T (on the right). The reason for this is that each multiplication by a Givens matrix on the right changes only two columns of R, thus requiring a mere O(n) arithmetic operations, which for n−1 Givens rotations sums up to O(n2) arithmetic operations; multiplying by the general n×n matrix Q would require O(n3) arithmetic operations. Likewise, storing the full Q matrix amounts to n2 elements, but each Givens matrix is fully specified the pairs (c,s) and (i,j), and n−1 of them can thus be stored in 4n−4 elements.

In the example, RQ=A3(G1TG2T)=(A3G1T)G2T≈[8.8687−1.55752.56072.99723.59650.966500−4.1843]G2T≈[8.86872.99720.02.9972−1.0430−3.57500−3.57502.1742]

## Complex matrices

A Givens rotation in the complex case would have to be a unitary matrix which maps a nonzero vector (wz)∈ℂ2 to some (r0). A straightforward solution for this is 1|w|2+|z|2(w‾z‾−zw) which is even in SU(2) and makes r real =|w|2+|z|2.

(Golub Van Loan) suggest the specialised form (cos⁡(θ)−sin⁡(θ)eiϕsin⁡(θ)e−iϕcos⁡(θ)) (coinciding with the above when w is real) for a Givens rotation. Their idea is to choose θ and ϕ so that eiϕ=z‾|z|/w‾|w| |w|sin⁡(θ)+|z|cos⁡(θ)=0 and they explain how to obtain cos⁡(θ),sin⁡(θ),cos⁡(ϕ),sin⁡(ϕ) from three calls to a function for computing real Givens rotations. This more complicated initialisation can be justified by the observation that since half the matrix elements are real, fewer arithmetic operations are needed when applying this rotation. Note however that having only two real degrees of freedom means the r component of the result cannot in general be made real.

A more elementary approach to the same end is to first multiply both rows being targeted by unit magnitude complex numbers of appropriate phase, so that both elements in the column considered become real – then a real Givens rotation suffices for zeroing out one of those entires. In the same notation as above, this amounts to 1|w|2+|z|2(|w||z|−|z||w|)⏟G(w‾/|w|00z‾/|z|)⏟D(wz)=(|w|2+|z|20) where D is unitary (but in general not special unitary) because it is a diagonal matrix whose diagonal elements have unit magnitudes, and the product GD is unitary because a product of unitary matrices is unitary. Here we save some arithmetic operations because multiplication by D acts on each row separately, and multiplication by G has real coefficients throughout.

A potential concern with the latter two methods is however that the choice of rotation is discontinuous along the w=0 line, and for the last method also along the z=0 line; even though the result of applying the rotation to (wz) varies continuously, the result of applying that same rotation to other columns of a matrix does not. For example,

the Golub–Van Loan method picks (ε1+ε2eiα11+ε2−e−iα11+ε2ε1+ε2) to rotate (εeiα1010), producing (eiα1+ε210ε1+ε20−10e−iα11+ε2).

## In Clifford algebras

In Clifford algebras and its child structures such as geometric algebras, rotations are represented by bivectors. Givens rotations are represented by the exterior product of the basis vectors. Given any pair of basis vectors 𝐞i,𝐞j Givens rotations bivectors are:

Bij=𝐞i∧𝐞j.

Their action on any vector is written:

v=e−(θ/2)(𝐞i∧𝐞j)ue(θ/2)(𝐞i∧𝐞j),

where

e(θ/2)(𝐞i∧𝐞j)=cos⁡(θ/2)+sin⁡(θ/2)𝐞i∧𝐞j.

## Dimension 3

See also: Euler angles and Davenport rotations

There are three Givens rotations in dimension 3:

RX(θ)=[1000cos⁡θ−sin⁡θ0sin⁡θcos⁡θ].

RY(θ)=[cos⁡θ0−sin⁡θ010sin⁡θ0cos⁡θ][note 1]

RZ(θ)=[cos⁡θ−sin⁡θ0sin⁡θcos⁡θ0001]

Given that they are endomorphisms they can be composed with each other as many times as desired, keeping in mind that g ∘ f ≠ f ∘ g.

These three Givens rotations composed can generate any rotation matrix according to Davenport's chained rotation theorem. This means that they can transform the standard basis of the space to any other frame in the space.[clarification needed]

When rotations are performed in the right order, the values of the rotation angles of the final frame will be equal to the Euler angles of the final frame in the corresponding convention. For example, an operator R=RY(θ3)⋅RX(θ2)⋅RZ(θ1) transforms the basis of the space into a frame with angles roll, pitch and yaw YPR=(θ3,θ2,θ1) in the Tait–Bryan convention z-x-y (convention in which the line of nodes is perpendicular to z and Y axes, also named Y-X′-Z″).

For the same reason, any rotation matrix in 3D can be decomposed in a product of three of these rotation operators.

The meaning of the composition of two Givens rotations g ∘ f is an operator that transforms vectors first by f and then by g, being f and g rotations about one axis of basis of the space. This is similar to the extrinsic rotation equivalence for Euler angles.

### Table of composed rotations

The following table shows the three Givens rotations equivalent to the different Euler angles conventions using extrinsic composition (composition of rotations about the basis axes) of active rotations and the right-handed rule for the positive sign of the angles.

The notation has been simplified in such a way that c1 means cos θ1 and s2 means sin θ2). The subindexes of the angles are the order in which they are applied using extrinsic composition (1 for intrinsic rotation, 2 for nutation, 3 for precession)

As rotations are applied just in the opposite order of the Euler angles table of rotations, this table is the same but swapping indexes 1 and 3 in the angles associated with the corresponding entry. An entry like zxy means to apply first the y rotation, then x, and finally z, in the basis axes.

All the compositions assume the right hand convention for the matrices that are multiplied, yielding the following results.

xzx | [c2−c1s2s1s2c3s2c3c2c1−s3s1−c2c3s1−c1s3s2s3c3s1+c1c2s3c3c1−c2s3s1] | xzy | [c2c3−c3s2c1+s3s1c3s2s1+s3c1s2c1c2−c2s1−s3c2s3s2c1+c3s1−s3s2s1+c3c1]

|
|
|

xyx | [c2s1s2c1s2s2s3c3c1−c2s3s1−c3s1−c1c2s3−c3s2c3c2s1+c1s3c3c2c1−s3s1] | xyz | [c3c2−s3c1+c3s2s1s3s1+c3s2c1s3c2c3c1+s3s2s1−c3s1+s3s2c1−s2c2s1c2c1]
yxy | [c3c1−c2s3s1s2s3c3s1+s3c2c1s1s2c2−c1s2−c2c3s1−c1s3c3s2c3c2c1−s3s1] | yxz | [c3c1−s3s2s1−s3c2c3s1+s3s2c1s3c1+c3s2s1c3c2s3s1−c3s2c1−c2s1s2c2c1]
yzy | [c3c2c1−s3s1−c3s2c2c3s1+c1s3c1s2c2s1s2−c3s1−c1c2s3s2s3c3c1−c2s3s1] | yzx | [c2c1−s2c2s1c3s2c1+s3s1c3c2c3s2s1−s3c1s3s2c1−c3s1s3c2s3s2s1+c3c1]
zyz | [c3c2c1−s3s1−c2s1c3−c1s3c3s2c3s1+c1c2s3c3c1−c2s3s1s2s3−c1s2s1s2c2] | zyx | [c2c1−c2s1s2s3s2c1+c3s1−s3s2s1+c3c1−s3c2−c3s2c1+s3s1c3s2s1+s3c1c3c2]
zxz | [c3c1−c2s1s3−c3s1−c1c2s3s2s3c2c3s1+c1s3c3c2c1−s3s1−c3s2s1s2c1s2c2] | zxy | [c3c1+s3s2s1−c3s1+s3s2c1s3c2c2s1c2c1−s2−s3c1+c3s2s1s3s1+c3s2c1c3c2]

## See also

* Jacobi rotation
* Plane of rotation
* Householder transformation
* Davenport rotations

## Notes

1. ↑ The RY(θ) rotation matrix immediately below is not a Givens rotation. The RY(θ) matrix immediately below respects the right-hand rule and is this usual matrix one sees in Computer Graphics; however, a Givens rotation is simply a matrix as defined in the Matrix representation section above and does not necessarily respect the right-hand rule. The matrix below is actually the Givens rotation through an angle of -θ.

RY(θ)=[cos⁡θ0sin⁡θ010−sin⁡θ0cos⁡θ]

## Citations

1. ↑ Björck, Ake (1996) (in en). Numerical Methods for Least Squares Problems. United States: SIAM. p. 54. ISBN 9780898713602. https://books.google.com/books?id=aQD1LLYz6tkC. Retrieved 16 August 2016.
2. ↑ Anderson, Edward (4 December 2000). "Discontinuous Plane Rotations and the Symmetric Eigenvalue Problem". University of Tennessee at Knoxville and Oak Ridge National Laboratory. http://www.netlib.org/lapack/lawnspdf/lawn150.pdf. Retrieved 16 August 2016.

## References

* Bindel, D. (2000), On Computing Givens rotations reliably and efficiently, http://www.netlib.org/lapack/lawns/downloads/ . LAPACK Working Note 148, University of Tennessee, UT-CS-00-449, January 31, 2001.
* Cybenko, George (March–April 2001), "Reducing Quantum Computations to Elementary Unitary Operations", Computing in Science and Engineering 3 (2): 27–32, doi:10.1109/5992.908999, Bibcode: 2001CSE.....3b..27C, http://vlsicad.eecs.umich.edu/Quantum/papers/QC-Unitary.pdf, retrieved 2009-02-26
* Golub, Gene H.; Van Loan, Charles F. (1996), Matrix Computations (3rd ed.), Johns Hopkins, ISBN 978-0-8018-5414-9 .
* Golub, Gene H.; Van Loan, Charles F. (2013), Matrix Computations (4th ed.), Johns Hopkins, ISBN 978-1-4214-0794-4 .
* Press, WH; Teukolsky, SA; Vetterling, WT; Flannery, BP (2007), "Section 11.3.1. Givens Method", Numerical Recipes: The Art of Scientific Computing (3rd ed.), New York: Cambridge University Press, ISBN 978-0-521-88068-8, http://apps.nrbook.com/empanel/index.html#pg=578, retrieved 2011-08-13

* v
* t
* e

Numerical linear algebra

Key concepts|

* Floating point
* Numerical stability

Problems|

* System of linear equations
* Matrix decompositions
* Matrix multiplication (algorithms)
* Matrix splitting
* Sparse problems

Hardware|

* CPU cache
* TLB
* Cache-oblivious algorithm
* SIMD
* Multiprocessing

Software|

* MATLAB
* Basic Linear Algebra Subprograms (BLAS)
* LAPACK
* Specialized libraries
* General purpose software

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Givens rotation. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Givens_rotation&oldid=3986408"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template