Why not see what MATLAB thinks you are giving it? When you get an error, think about what it is telling you. Then use MATLAB to see what your code does. GET YOUR HANDS DIRTY.
2*x*exp(-x) - x^2*exp(-x)
See that when you created the function handle a, you never told MATLAB that k was actually a function of x. You might have tried this instead:
a = @(x) double(subs(k,x));
So now MATLAB can evaluate a as a function of x.
It seems to work now. Of course, simpler was just: