Possible wrong gradient in my book, need confirmation While reading this chapter about iterative algorithms, I came up with the following function and it's gradient.

I just can't find the same gradient showed. I tried two different approaches and both disagree with the book. Now I'm starting to think they made some mistake and I just need to confirm whether this is the case or not. 
By the way, one of my computations is the following. 
$$\frac{\partial f}{\partial x_i}(x) = \lim_{t\to 0} \frac{f(x+te_i)-f(x)}{t} = \lim_{t\to 0} \frac{\frac{1}{2}(x+te_i)^TA(x+te_i) -b^T(x+te_i)- \frac{1}{2}x^TAx + b^Tx}{t} =$$
$$= \lim_{t\to0} \frac{\frac{1}{2}(x^TAx + te^T_iAx + tx^Te_i + t^2e_i^Te_i) -b^Tx - tb^Te_i -\frac{1}{2}x^TAx + b^Tx}{t} = $$
$$= \lim_{t\to0} \frac{e^T_iAx + x^Te_i + te^T_ie_i - 2b^Te_i}{2} = \frac{e^T_iAx + x^Te_i - 2b^Te_i}{2} = \frac{(Ax)_i + x_i-2b_i}{2},$$
where $(Ax)_i$ is the ith line of $Ax$. Therefore, $\nabla f(x) = \frac{Ax + x - 2b}{2}$ or $\frac{Ax+x}{2}-b$. Anyway, the resulty doesn't match. Also, if the book indeed made a mistake, what should be the function $f$ to get that gradient?
Thanks. 
 A: Ok so this is how I would have handled it, the part containing b is perfectly fine, so in essence I will differentiate the matrix part, all factors of $\frac{1}{2}$ will be moved out front. The first step is fine:
$$
\frac{\partial f}{\partial x_i} = \lim_{t \to 0} \frac{f(x + t e_i) - f(x)}{t} = \frac{1}{2}\lim_{t \to 0}\frac{(x+te_i)^TA(x + te_i) -x^T A x }{t}
$$
I will use the steps involved in proving the product rule, we add zero to the numerator in the form:
\begin{eqnarray*}
& &\frac{1}{2}\lim_{t \to 0}\frac{(x+te_i)^TA(x + te_i) -x^T A x }{t} = \\
 & &\frac{1}{2}\lim_{t \to 0}\frac{(x+te_i)^TA(x + te_i)-(x+te_i)^TAx + (x+te_i)^TAx -x^T A x }{t}
\end{eqnarray*}
Then split the limit into two limits
$$
\frac{1}{2}\lim_{t \to 0}\frac{(x+te_i)^TA(x + te_i)-(x+te_i)^TAx + (x+te_i)^TAx -x^T A x }{t} =
\lim_{t \to 0}\frac{1}{2}\frac{(x+te_i)^TA(x + te_i)-(x+te_i)^TAx}{t} + \lim_{t \to 0}\frac{1}{2}\frac{(x+te_i)^TAx -x^T A x}{t}
$$
Finally factor out like terms in both limits
$$
\frac{1}{2}\lim_{t \to 0} (x+te_i)^T A \frac{(x+te_i) - x}{t} + 
\frac{1}{2}\lim_{t \to 0} \frac{(x+te_i)^T - x^T}{t}Ax 
$$
These limits simplify easily (essentially they represent derivatives of the vectors themselves), So this all boils down to
$$
\frac{1}{2}e_i^T A x + \frac{1}{2}x^T A e_i =  e_i^T A x
$$
The last equality usually stems from A being a symmetric matrix
A: Partial derivatives of that troublesome first term are a straightforward calculation that doesn’t require any particular tricks:$$\begin{align}
\frac\partial{\partial x_i}(x^TAx) &= \lim_{h\to0}\frac1h[(x+he_i)^TA(x+he_i)-x^TAx] \\
&= \lim_{h\to0}\frac1h(x^TAx+he_i^TAx+hx^TAe_i+h^2e_i^TAe_i-x^TAx) \\
&= e_i^TAx+x^TAe_i \\
&= 2e_i^TAx \\
&= 2A_ix,
\end{align}$$ using the distributive law in the first step and symmetry of $A$ in the penultimate step. $A_i$ denotes the $i$th row of $A$.  
You started down the right track in your own calculation, but when you expanded $(x+he_i)^TA(x+he_i)$ you left out a factor of $A$ in the third and fourth terms, which left you with $x_i$ instead of a second $(Ax)_i$ after taking the limit.
