3x3 Givens Rotation

In [4]:
import numpy as np
In [5]:
a = np.random.randn(3)
a
Out[5]:
array([ 0.73090072,  1.77355794,  0.80801157])

Let's zero out $a_2$:

In [7]:
G = np.zeros((3, 3))

c = a[0]/np.sqrt(a[0]**2 + a[1]**2)
s = a[1]/np.sqrt(a[0]**2 + a[1]**2)

G[:2,:2] = np.array([
        [c, s],
        [-s, c]
        ])
G
Out[7]:
array([[ 0.38102265,  0.9245657 ,  0.        ],
       [-0.9245657 ,  0.38102265,  0.        ],
       [ 0.        ,  0.        ,  0.        ]])

Anything wrong with $G$?

(Edit this cell for solution.)

How would we fix that issue?

In [11]:
G[2,2] = 1
In [10]:
G @ a
Out[10]:
array([ 1.91826057,  0.        ,  0.80801157])

Observations?