# Solving for vector in linear algebra

This is not really my field so please bear with me. In the equation:

$(X^TX)\hat{h}_q = X^Ty_q$

I need to find the vector $\hat{h}_q$. $X$ and $y_q$ are known, and $y_q$ is the same length as $\hat{h}_q$.

$X$ is a matrix of the form:

$$X = \begin{pmatrix} 1 & 0 & 0 &0 \\ 2&1&0&0\\3&2&1&0\\4&3&2&1\\0&4&3&2\\0&0&4&3\\0&0&0&4\end{pmatrix}$$

but instead of 1 - 4 it's a vector of random numbers about 3500 long.

-
This is not what I would call a diagonal matrix. – Gerry Myerson Mar 12 '13 at 0:05

$h_q = (X^TX)^{-1}X^Ty_q$. Use matlab or octave to find $X^TX$ and its inverse.
Thank you, this is helpful, but it's causing some unhappyness with Matlab. If $X$ is a 100 row by 50 col matrix, then $(X^TX)^{-1}X^T$ is a 50 row by 100 col matrix, correct? If y is then a 200-element column vector, I cannot multiply them together it seems? (at least, matlab says dimensions do not agree). – Jordan Mar 12 '13 at 0:34
Your question has $X^Ty_q$ in it. If $X$ is $100\times50$ and $y_q$ is $200\times1$ then your question makes no sense. – Gerry Myerson Mar 12 '13 at 12:37
@GerryMyerson Yes, I realized I have to modify $X$ depending on the length of $y_q$. Sorry for the confusion there. I have now hit a second problem though: my $X$ is 7000x10000, and trying to find the inverse of that is crashing Matlab on even the most powerful computer in our lab. Is there any way to do it in a way that won't cause that problem? – Jordan Mar 12 '13 at 23:11