Template:Short description 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.
As action on matricesEdit
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 <math>x_1</math> through <math>x_n</math> and the elements of the other target row by <math>y_1</math> through <math>y_n</math>: <math display="block">
\begin{bmatrix} \vdots & \vdots & \ddots & \vdots \\ x_1 & x_2 & \dots & x_n \\ \vdots & \vdots & \ddots & \vdots \\ y_1 & y_2 & \dots & y_n \\ \vdots & \vdots & \ddots & \vdots \end{bmatrix}
</math> Then the effect of a Givens rotation is to rotate each subvector <math>(x_k,y_k)</math> 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 <math>(x_k,y_k)</math> by the same angle, but here these named elements occur in the matrix as <math display="block">
\begin{bmatrix} \dots & x_1 & \dots & y_1 & \dots \\ \dots & x_2 & \dots & y_2 & \dots \\ \ddots & \vdots & \ddots & \vdots & \ddots \\ \dots & x_n & \dots & y_n & \dots \end{bmatrix}
</math> 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 representationEdit
A Givens rotation is represented by a matrix of the form
- <math>G(i, j, \theta) =
\begin{bmatrix} 1 & \cdots & 0 & \cdots & 0 & \cdots & 0 \\ \vdots & \ddots & \vdots & & \vdots & & \vdots \\ 0 & \cdots & c & \cdots & -s & \cdots & 0 \\ \vdots & & \vdots & \ddots & \vdots & & \vdots \\ 0 & \cdots & s & \cdots & c & \cdots & 0 \\ \vdots & & \vdots & & \vdots & \ddots & \vdots \\ 0 & \cdots & 0 & \cdots & 0 & \cdots & 1 \end{bmatrix},</math>
where Template:Math and Template:Math appear at the intersections Template:Mvarth and Template:Mvarth rows and columns. That is, for fixed Template:Mvar Template:Mvar Template:Mvar, the non-zero elements of Givens matrix are given by:
- <math>\begin{align}
g_{kk} &{}= 1 \qquad \text{for} \ k \ne i,\,j\\ g_{kk} &{}= c \qquad \text{for} \ k = i,\,j\\ g_{ji} &{} = -g_{ij}= -s\\
\end{align}</math>
The product Template:Math represents a counterclockwise rotation of the vector Template:Math in the Template:Math plane of Template:Mvar radians, hence the name Givens rotation.
Stable calculationEdit
When a Givens rotation matrix, Template:Math, multiplies another matrix, Template:Mvar, from the left, Template:Math, only rows Template:Mvar and Template:Mvar of Template:Mvar are affected. Thus we restrict attention to the following counterclockwise problem. Given Template:Mvar and Template:Mvar, find Template:Math and Template:Math such that
- <math> \begin{bmatrix} c & -s \\ s & c \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} r \\ 0 \end{bmatrix} , </math>
where <math> r = \sqrt{a^2 + b^2} </math> is the length of the vector <math>(a,b)</math>. Explicit calculation of Template:Mvar is rarely necessary or desirable. Instead we directly seek Template:Mvar and Template:Mvar. An obvious solution would be
- <math>\begin{align}
c &{}\larr a / r \\ s &{}\larr -b / r.
\end{align}</math><ref>Template:Cite book</ref>
However, the computation for Template:Mvar may overflow or underflow. An alternative formulation avoiding this problem Template:Harv 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.
<syntaxhighlight lang=fortran> 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 </syntaxhighlight>
Furthermore, as Edward Anderson discovered in improving LAPACK, a previously overlooked numerical consideration is continuity. To achieve this, we require Template:Mvar to be positive.<ref>{{#invoke:citation/CS1|citation
|CitationClass=web
}}</ref> The following MATLAB/GNU Octave code illustrates the algorithm.
<syntaxhighlight lang="matlab"> 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 </syntaxhighlight>
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, Template:Math, using the abs and sgn functions, is an alternative as done above.
TriangularizationEdit
Given the following Template:Gaps Matrix:
- <math> A_1 =
\begin{bmatrix} 6 & 5 & 0 \\ 5 & 1 & 4 \\ 0 & 4 & 3 \\ \end{bmatrix},</math>
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 Template:Gaps and Template:Gaps is required; element Template:Gaps is zeroed first, using a rotation matrix of:
- <math>G_{1} =
\begin{bmatrix} c & -s & 0 \\ s & c & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}.</math>
The following matrix multiplication results:
- <math>
\begin{align} G_1 A_1 &{}= A_2 \\ &{} = \begin{bmatrix} c & -s & 0 \\
s & c & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} 6 & 5 & 0 \\ 5 & 1 & 4 \\ 0 & 4 & 3 \\ \end{bmatrix},
\end{align} </math>
where
- <math>\begin{align}
r &{}= \sqrt{6^2 + 5^2} \approx 7.8102 \\ c &{}= 6 / r \approx 0.7682 \\ s &{}= -5 / r \approx -0.6402.
\end{align} </math>
Using these values for Template:Mvar and Template:Mvar and performing the matrix multiplication above yields Template:Mvar:
- <math>A_2 \approx \begin{bmatrix} 7.8102 & 4.4813 & 2.5607 \\
0 & -2.4327 & 3.0729 \\ 0 & 4 & 3 \\ \end{bmatrix}</math>
Zeroing element Template:Gaps finishes off the process. Using the same idea as before, the rotation matrix is:
- <math>G_{2} =
\begin{bmatrix} 1 & 0 & 0 \\ 0 & c & -s \\ 0 & s & c \\ \end{bmatrix}</math>
Afterwards, the following matrix multiplication is:
- <math>
\begin{align} G_2 A_2 &{}= A_3 \\ &{}\approx \begin{bmatrix} 1 & 0 & 0 \\
0 & c & -s \\ 0 & s & c \\ \end{bmatrix} \begin{bmatrix} 7.8102 & 4.4813 & 2.5607 \\ 0 & -2.4327 & 3.0729 \\ 0 & 4 & 3 \\ \end{bmatrix},
\end{align} </math>
where
- <math>\begin{align}
r &{}\approx \sqrt{(-2.4327)^2 + 4^2} \approx 4.6817 \\ c &{}\approx -2.4327 / r \approx -0.5196 \\ s &{}\approx -4 / r \approx -0.8544.
\end{align} </math> Using these values for Template:Mvar and Template:Mvar and performing the multiplications results in Template:Mvar:
- <math>A_3 \approx
\begin{bmatrix} 7.8102 & 4.4813 & 2.5607 \\ 0 & 4.6817 & 0.9665 \\ 0 & 0 & -4.1843 \\ \end{bmatrix}.
</math>
This new matrix Template:Mvar is the upper triangular matrix needed to perform an iteration of the QR decomposition. Template:Mvar is now formed using the transpose of the rotation matrices in the following manner:
- <math>Q = G_{1}^T\, G_{2}^T.
</math>
Performing this matrix multiplication yields:
- <math>Q \approx
\begin{bmatrix} 0.7682 & 0.3327 & 0.5470 \\ 0.6402 & -0.3992 & -0.6564 \\ 0 & 0.8544 & -0.5196 \\ \end{bmatrix}.</math>
This completes two iterations of the Givens Rotation and calculating the QR decomposition can now be done.
QR iteration variantEdit
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 <math> RQ </math>, but one should not do so by first multiplying <math> G_{1}^T </math> and <math> G_{2}^T </math> to form <math> Q </math>, instead rather by multiplying each <math> G_k^T </math> by <math> R G_1^T \dots G_{k-1}^T </math> (on the right). The reason for this is that each multiplication by a Givens matrix on the right changes only two columns of <math> R </math>, thus requiring a mere <math> O(n) </math> arithmetic operations, which for <math> n-1 </math> Givens rotations sums up to <math> O(n^2) </math> arithmetic operations; multiplying by the general <math> n \times n </math> matrix <math>Q</math> would require <math> O(n^3) </math> arithmetic operations. Likewise, storing the full <math>Q</math> matrix amounts to <math>n^2</math> elements, but each Givens matrix is fully specified by its pair <math>(c,s)</math> and <math> n-1 </math> of them can thus be stored in <math> 2n-2 </math> elements.
In the example, <math display="block">
\begin{aligned} R Q = A_3 (G_1^T G_2^T) ={}& (A_3 G_1^T) G_2^T \\ \approx{}& \begin{bmatrix} 8.8687& -1.5575& 2.5607\\ 2.9972& 3.5965& 0.9665\\ 0& 0& -4.1843 \end{bmatrix} G_2^T \approx \begin{bmatrix} 8.8687& 2.9972& 0.0\\ 2.9972&-1.0430&-3.5750\\ 0& -3.5750& 2.1742 \end{bmatrix} \end{aligned}
</math>
Complex matricesEdit
Another method can extend Givens rotations to complex matrices. A diagonal matrix whose diagonal elements have unit magnitudes but arbitrary phases is unitary. Let A be a matrix for which it is desired to make the ji element be zero using the rows and columns i and j>i. Let D be a diagonal matrix whose diagonal elements are one except the ii and jj diagonal elements which also have unit magnitude but have phases which are to be determined. The phases of the ii and jj elements of D can be chosen so as to make the ii and ji elements of the product matrix D A be real. Then a Givens rotation G can be chosen using the i and j>i rows and columns so as to make the ji element of the product matrix G D A be zero. Since a product of unitary matrices is unitary, the product matrix G D is unitary and so is any product of such matrix pair products.
In Clifford algebrasEdit
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 <math>\mathbf e_i, \mathbf e_j</math> Givens rotations bivectors are:
- <math>B_{ij} = \mathbf e_i \wedge \mathbf e_j.</math>
Their action on any vector is written:
- <math>v=e^{-(\theta/2)(\mathbf e_i \wedge \mathbf e_j)}u e^{(\theta/2)(\mathbf e_i \wedge \mathbf e_j)},</math>
where
- <math>e^{(\theta/2)(\mathbf e_i \wedge \mathbf e_j)}= \cos(\theta/2)+ \sin(\theta/2) \mathbf e_i \wedge \mathbf e_j.</math>
Dimension 3Edit
There are three Givens rotations in dimension 3:
- <math>
R_X(\theta) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \end{bmatrix}. </math>
- <math>\begin{align} \\
R_Y(\theta) = \begin{bmatrix} \cos \theta & 0 & -\sin \theta \\ 0 & 1 & 0 \\ \sin \theta & 0 & \cos \theta \end{bmatrix} \end{align} </math><ref group="note">The <math>R_Y(\theta)</math> rotation matrix immediately below is not a Givens rotation. The <math>R_Y(\theta)</math> 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 -<math>\theta</math>.
- <math>
R_Y(\theta) = \begin{bmatrix} \cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ -\sin \theta & 0 & \cos \theta \end{bmatrix} </math> </ref>
- <math>\begin{align} \\
R_Z(\theta) = \begin{bmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{bmatrix} \end{align} </math>
Given that they are endomorphisms they can be composed with each other as many times as desired, keeping in mind that Template:Math.
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.Template:Clarify
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 <math>R = R_Y(\theta_3)\cdot R_X(\theta_2)\cdot R_Z(\theta_1)</math> transforms the basis of the space into a frame with angles roll, pitch and yaw <math>YPR = (\theta_3,\theta_2,\theta_1)</math> 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 Template:Math is an operator that transforms vectors first by Template:Mvar and then by Template:Mvar, being Template:Mvar and Template:Mvar rotations about one axis of basis of the space. This is similar to the extrinsic rotation equivalence for Euler angles.
Table of composed rotationsEdit
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 Template:Math means Template:Math and Template:Math means Template:Math. 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 <math>\begin{bmatrix} c_2 & - c_1 s_2 & s_1 s_2 \\ c_3 s_2 & c_3 c_2 c_1 - s_3 s_1 & - c_2 c_3 s_1 - c_1 s_3 \\ s_2 s_3 & c_3 s_1 + c_1 c_2 s_3 & c_3 c_1 - c_2 s_3 s_1
\end{bmatrix}</math>
xzy <math>\begin{bmatrix} c_2 c_3 & - c_3 s_2 c_1 + s_3 s_1 & c_3 s_2 s_1 + s_3 c_1 \\ s_2 & c_1 c_2 & - c_2 s_1 \\ - s_3 c_2 & s_3 s_2 c_1+c_3 s_1 & -s_3 s_2 s_1 + c_3 c_1 \end{bmatrix}</math>
xyx <math>\begin{bmatrix} c_2 & s_1 s_2 & c_1 s_2 \\ s_2 s_3 & c_3 c_1 - c_2 s_3 s_1 & - c_3 s_1 - c_1 c_2 s_3 \\ -c_3 s_2 & c_3 c_2 s_1 + c_1 s_3 & c_3 c_2 c_1 - s_3 s_1 \end{bmatrix}</math>
xyz <math>\begin{bmatrix} c_3 c_2 & -s_3 c_1 + c_3 s_2 s_1 & s_3 s_1 + c_3 s_2 c_1 \\ s_3 c_2 & c_3 c_1 + s_3 s_2 s_1 & -c_3 s_1 + s_3 s_2 c_1 \\ -s_2 & c_2 s_1 & c_2 c_1 \end{bmatrix}</math>
yxy <math>\begin{bmatrix} c_3 c_1 - c_2 s_3 s_1 & s_2 s_3 & c_3 s_1 + s_3 c_2 c_1 \\ s_1 s_2 & c_2 & - c_1 s_2 \\ -c_2 c_3 s_1 - c_1 s_3 & c_3 s_2 & c_3 c_2 c_1 - s_3 s_1
\end{bmatrix}</math>
yxz <math>\begin{bmatrix} c_3 c_1-s_3 s_2 s_1 & -s_3 c_2 & c_3 s_1+s_3 s_2 c_1 \\ s_3 c_1+c_3 s_2 s_1 & c_3 c_2 & s_3 s_1-c_3 s_2 c_1 \\ -c_2 s_1 & s_2 & c_2 c_1 \end{bmatrix}</math>
yzy <math>\begin{bmatrix} c_3 c_2 c_1 - s_3 s_1 & - c_3 s_2 & c_2 c_3 s_1 + c_1 s_3 \\
c_1 s_2 & c_2 & s_1 s_2 \\ -c_3 s_1 - c_1 c_2 s_3 & s_2 s_3 & c_3 c_1 - c_2 s_3 s_1
\end{bmatrix}</math>
yzx <math>\begin{bmatrix} c_2 c_1 & -s_2 & c_2 s_1 \\ c_3 s_2 c_1+s_3 s_1 & c_3 c_2 & c_3 s_2 s_1-s_3 c_1 \\ s_3 s_2 c_1-c_3 s_1 & s_3 c_2 & s_3 s_2 s_1+c_3 c_1 \end{bmatrix}</math>
zyz <math>\begin{bmatrix} c_3 c_2 c_1 - s_3 s_1 & - c_2 s_1 c_3 - c_1 s_3 & c_3 s_2 \\ c_3 s_1 + c_1 c_2 s_3 & c_3 c_1 - c_2 s_3 s_1 & s_2 s_3 \\
-c_1 s_2 & s_1 s_2 & c_2
\end{bmatrix}</math>
zyx <math>\begin{bmatrix} c_2 c_1 & -c_2 s_1 & s_2 \\ s_3 s_2 c_1+c_3 s_1 & -s_3 s_2 s_1+c_3 c_1 & -s_3 c_2 \\
-c_3 s_2 c_1+s_3 s_1 & c_3 s_2 s_1+s_3 c_1 & c_3 c_2 \end{bmatrix}</math>
zxz <math>\begin{bmatrix} c_3 c_1 - c_2 s_1 s_3 & - c_3 s_1 - c_1 c_2 s_3 & s_2 s_3 \\ c_2 c_3 s_1 + c_1 s_3 & c_3 c_2 c_1 - s_3 s_1 & - c_3 s_2 \\ s_1 s_2 & c_1 s_2 & c_2 \end{bmatrix}</math>
zxy <math>\begin{bmatrix} c_3 c_1+s_3 s_2 s_1 & -c_3 s_1+s_3 s_2 c_1 & s_3 c_2 \\ c_2 s_1 & c_2 c_1 & -s_2 \\
-s_3 c_1+c_3 s_2 s_1 & s_3 s_1+c_3 s_2 c_1 & c_3 c_2 \end{bmatrix}</math>
See alsoEdit
NotesEdit
CitationsEdit
ReferencesEdit
- Template:Citation. LAPACK Working Note 148, University of Tennessee, UT-CS-00-449, January 31, 2001.
- Template:Citation
- Template:Citation.
- Template:Citation