Find $a_1,a_2,a_3\in\mathbb{R}$ such that vectors $e_i=(x-a_i)^2,i=1,2,3$ form a basis for $\mathcal{P_2}$ (space of polynomials)
Attempt:
$e_1= \begin{bmatrix} 1 \\ -2a_1 \\ a_1^{2} \\ \end{bmatrix}$
$e_2= \begin{bmatrix} 1 \\ -2a_2 \\ a_2^{2} \\ \end{bmatrix}$
$e_3= \begin{bmatrix} 1 \\ -2a_3 \\ a_3^{2} \\ \end{bmatrix}$
Matrix of column vectors $e_i$ is $A= \begin{bmatrix} 1 & 1 & 1 \\ -2a_1 & -2a_2^2 & -2a_3^2 \\ a_1^2 & a_2^2 & a_3^2 \\ \end{bmatrix}$
$A$ must be invertible $\Rightarrow \det(A)\neq 0$
$\det(A)=-2(a_2a_3^2-a_2^2a_3-a_1a_3^2+a_1^2a_3+a_1a_2^2-a_1^2a_2)$
Question: How to factorize this function to get the conditions for $a_1,a_2,a_3$?
Every vector $e_i$ can be written as a linear comination of $e_i\Rightarrow e_i$ span $\mathcal{P_2}$
If $A$ is invertible, $e_i$ are linearly independent.
From the span and linear independence, set of $e_i$ form a basis for $\mathcal{P_2}$.
Hint:
Write $\det (A)=0$ as an equation in $a_1$ : $$ a_1^2(a_3-a_2)+a_1(a_2^2-a_3^2)+a_2a_3(a_3-a_2)=0 $$
Solve for $a_1$ this second degree equation, with $a_2$ and $a_3$ as parameter.
We have the discriminant $\Delta=(a_2-a_3)^4$ and the solutions, for $a_2 \ne a_3$, are $a_1=a_2$ or $a_1=a_3$ . Now you can find when the three column vectors are linearly independent and, as you have noted, they are a basis in$\mathbb{R}^3$.
Note that this result is the same as suggested by Milo Brandt in his comment (now I see it !).