<s>[INST] Trouble to find the solution to a linear system where a matrix is not invertible Hello community I am new here and I have a question which might be pretty basic.
So I am trying to solve an equation. I have 3 matrices
A =  \begin{pmatrix}1&0&0&0&0&0&0&0\\0&1&1&0&0&0&0&0\end{pmatrix}
B = \begin{pmatrix}0&0&0&0&0&0&1&0\\0&0&0&0&0&0&0&1\end{pmatrix}
and 
K = \begin{pmatrix}1&0&0&0&0&0&0&0\\0&1&1&0&0&0&0&0\\0&0&0&0&0&0&1&0\end{pmatrix}
H = \begin{pmatrix}A\\B\end{pmatrix}
and Z = \begin{pmatrix}z1\\z2\\z3\end{pmatrix}
And I have linear system 
$\begin{pmatrix}H\\K\end{pmatrix} v = \begin{pmatrix}0\\Z\end{pmatrix}$
It says that solution for determined system is 
$ v = \begin{bmatrix}\begin{pmatrix}H\\K\end{pmatrix}^T \begin{pmatrix}H\\K\end{pmatrix} \end{bmatrix} ^{-1}\begin{pmatrix}H\\K\end{pmatrix}^T \begin{pmatrix}0\\Z\end{pmatrix} $
Okay when I put this system of matrices in python it shows that matrix inside [] can't be inverse. I am presumping that 
H = \begin{pmatrix}A\\B\end{pmatrix} 
just means that 
H is 
\begin{pmatrix}1&0&0&0&0&0&0&0\\0&1&1&0&0&0&0&0\\0&0&0&0&0&0&1&0\\0&0&0&0&0&0&0&1\end{pmatrix}
Two matrices put together. Same I presume for \begin{pmatrix}H\\K\end{pmatrix} 
Where am I wrong?
Ps: sorry im new here hope I wrote everything correctly and understandable. Happy holidays everyone. 
 [/INST] For the sake of simpler notations, let us rename $$L:=\begin{pmatrix}H\\K\end{pmatrix} \ \ \text{and} \ \ P:=\begin{pmatrix}0\\Z\end{pmatrix} $$
giving :
$$Lv=P \tag{1}$$
which is a $7 \times 8$ system (thus an underdetermined system : less constraints than the number of unknowns).
Instead of your $$ v = (L^T L)^{-1}L^T P $$
which is a formula valid for overdetermined systems, one must take for an underdetermined system :
$$  v = L^T(L L^T)^{-1} P \tag{2}$$
(see https://see.stanford.edu/materials/lsoeldsee263/08-min-norm.pdf for the difference of formulas between under- and over-determined systems ; in this document, a matrix like $L$ with more columns than lines is called "fat").
This will give you a so-called "mean-squares" solution.
Proof of (1) : Plug (2) into (1), you will get :
$$\underbrace{L L^T(L L^T)^{-1}}_{\text{identity matrix} \ I} P=P...$$
</s>