The matrix $A$ is defined by $$
A=\begin{pmatrix}
1&5&1\\
1&-2&-2\\
2&3&\theta
\end{pmatrix}.
$$
(i) (a) Find the rank of $A$ when $\theta\ne-1$. [3]
(b) Find the rank of $A$ when $\theta=-1$. [1]
Consider the system of equations $$
\begin{aligned}
x+5y+z&=-1,\\
x-2y-2z&=0,\\
2x+3y+\theta z&=\theta.
\end{aligned}
$$
(ii) Solve the system of equations when $\theta\ne-1$. [3]
(iii) Find the general solution when $\theta=-1$. [3]
(iv) Show that if $\theta=-1$ and $\phi\ne-1$, then $$
A\mathbf x=\begin{pmatrix}-1\\0\\\phi\end{pmatrix}
$$ has no solution. [2]