## How to make X'X = aI

How to make X'X = aI

Let the $n \times 2$ matrix $X = [1, x]$, and $X^TX = aI$ where a is a scalar. What is $x$ then?

\begin{align*} X^TX &= \begin{pmatrix} 1^T1 & 1^Tx \\ x^T1 & x^Tx \\ \end{pmatrix} \end{align*}

This requires $\sum x_i = 0$ and $\sum x_i^2 = n$. Let $u = x / \sqrt{n}$, then $u^T u = 1$.

Now we can construct such an $x$ by constructing $u$ first. Let the vector v be a normalized (unit) vector, and let u(1:n/2) = v/sqrt(2); u((n/2+1):end) = -v/sqrt(2), then clearly we have $\sum u_i = 0$, and $u^Tu = 1$.

If we make $x = \sqrt{n} u$, then x satisfies the requirement.

Make X'X = nI (matlab)
Click to toggle code (may have to try twice)
nr = 100;
nc = 1;
x = rand(nr/2, nc)
x = orth(x)
x = x / sqrt(2)
x = vertcat(x, -x)
x = x * sqrt(nr)
size(x)
allones = repmat(1, nr, 1)
x = horzcat(allones, x)
y = rand(nr, 1);
btrue = inv(x' * x) * x' * y
A = x' * x