<s>[INST] For which $k \in \mathbb{R}$ the vector $(1,k^2-k,k) \in Im(f)$ where $f$ is a linear map? Let $f:\mathbb{R^3}\to \mathbb{R^3} $ the map defined by $A_h$
$$
     A_h=   \begin{pmatrix}
        2 & 1 & -1 \\
        1 & 2 & 1 \\
        -1 & 1 & h \\
        \end{pmatrix}
$$
where $h \in \mathbb{R}$.  $f(x,y,z)=(x-y-2z,x+2y+z,3y+3z)$
I have found the value of $h$ for which $\dim(\ker(f))>0$ which is $h=2$.
Then a basis of $Im(f)$ is $\{(1,2,1),(-1,1,2)\}$.
$$
     A_2=   \begin{pmatrix}
        2 & 1 & -1 \\
        1 & 2 & 1 \\
        -1 & 1 & 2 \\
        \end{pmatrix}
$$
I have to determine for which $k \in \mathbb{R}$ the vector $v=(1,k^2-k,k) \in Im(f)$ (with $h=2$). 
My attempt 
I tried to find $k$ such that $v$ is equal to the linear combination of the two vectors of $Im(f)$, but it does not work.
I also tried to find $k$ such that $v$ is equal to $(x-y-2z,x+2y+z,3y+3z)$ and I got $k=1+\sqrt{2}$ or $k=1-\sqrt{2}$, but I think I am wrong.
What is the right approach? 
 [/INST] $$a(1,2,1) + b(-1,1,2) = (1,k^2-k,k)$$
Separating components:
$$\begin{cases}
a - b &=& 1 &(1) \\
2a + b &=& k^2-k &(2) \\
a+2b &=& k &(3)
\end{cases}$$
$(1)+(3)$ gives:
$$2a+b=k+1$$
Comparing it with $(2)$ gives:
$$k^2-k=k+1$$
Solving the quadratic equation gives:
$$k=\dfrac{2\pm\sqrt{8}}{2}=1\pm\sqrt2$$
We're basically done here.

Let $k=1+\sqrt2$.
$(3)-(1)$ gives:
$$3b=k-1=\sqrt2$$
Thus:
$$\begin{cases}
a &=& \dfrac{\sqrt2}{3}+1\\
b &=& \dfrac{\sqrt2}3
\end{cases}$$
Checking:
$$\begin{cases}
a - b &=& 1 \\
2a + b &=& 2+\sqrt2 \\
a+2b &=& 1+\sqrt2
\end{cases}$$

Let $k=1-\sqrt2$.
$(3)-(1)$ gives:
$$3b=k-1=-\sqrt2$$
Thus:
$$\begin{cases}
a &=& -\dfrac{\sqrt2}{3}+1\\
b &=& -\dfrac{\sqrt2}3
\end{cases}$$
Checking:
$$\begin{cases}
a - b &=& 1 \\
2a + b &=& 2-\sqrt2 \\
a+2b &=& 1-\sqrt2
\end{cases}$$
</s>