givens.RdGivens Rotations and QR decomposition
givens(A)givens(A) returns a QR decomposition (or factorization) of the
square matrix A by applying unitary 2-by-2 matrices U such
that U * [xk;xl] = [x,0] where x=sqrt(xk^2+xl^2)
List with two matrices Q and R, Q orthonormal and
R upper triangular, such that A=Q%*%R.
Golub, G. H., and Ch. F. van Loan (1996). Matrix Computations. Third edition, John Hopkins University Press, Baltimore.
## QR decomposition
A <- matrix(c(0,-4,2, 6,-3,-2, 8,1,-1), 3, 3, byrow=TRUE)
gv <- givens(A)
(Q <- gv$Q); (R <- gv$R)
#> [,1] [,2] [,3]
#> [1,] 0.0 -0.80 0.60
#> [2,] 0.6 -0.48 -0.64
#> [3,] 0.8 0.36 0.48
#> [,1] [,2] [,3]
#> [1,] 10 -1 -2
#> [2,] 0 5 -1
#> [3,] 0 0 2
zapsmall(Q %*% R)
#> [,1] [,2] [,3]
#> [1,] 0 -4 2
#> [2,] 6 -3 -2
#> [3,] 8 1 -1
givens(magic(5))
#> $Q
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.5233867 0.5057542 -0.67346976 0.12154153 0.04410384
#> [2,] 0.7081114 -0.6965734 0.01772741 -0.08154163 0.08000231
#> [3,] 0.1231498 0.1367418 0.35575062 0.63074410 0.66463461
#> [4,] 0.3078745 0.1910574 0.41223097 0.42467160 -0.72002083
#> [5,] 0.3386620 0.4514387 0.49963121 -0.63276736 0.17744103
#>
#> $R
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 32.48076 26.63115 21.39728 23.706339 25.861461
#> [2,] 0.00000 19.89427 12.32344 1.943926 4.085579
#> [3,] 0.00000 0.00000 24.39855 11.631551 3.741480
#> [4,] 0.00000 0.00000 0.00000 20.098200 9.973936
#> [5,] 0.00000 0.00000 0.00000 0.000000 16.000463
#>