I'm a bit new to linear algebra. I have a question about why the solution to the differential equation
$y''+2y'+y+x=0$
is not a subspace of the vector space of all twice differentiable functions. When I solve the equation using the method of unknown coefficients, I get the general solution
$y = C_1e^x+C_2xe^x-x+2$
By my line of thinking, this function is twice differentiable for all values $C_1$ and $C_2$, so all solutions are members of the given set. However, the sum of any two solutions, for example
$(C_1e^x+C_2xe^x-x+2) + (B_1e^x+B_2xe^x-x+2) = e^x(C_1+B_1)+xe^x(C_2+B_2)-2x+4$
Where the expression $-2x+4$ does not satisfy the particular solution. Am I on the right track, or is there another reason that it is not a subspace?
In general, the solutions of an homogeneous ODE form a vector subspace of the space of twice diffentiable functions. But, here, you have a term $x$ in your equation. So your space of solution is an affine subspace directed by the vector subspace
$V = <e^x,xe^x>$
and containing a particular solution, for example $-x+2$. Also, you could directly check $0$ is not a solution, so this is not a vector subspace.