How do I calculate the gradient of a function in a $n$-dimensional space? $q(x)=x^TAx+b^Tx+c$
$A$ is matrix. $x,b\in \mathbb{R}^n$ and  $c\in \mathbb{R}$ 
I really don't know how to calculate it for this function.
 A: I like to do this component wise, using $\partial_k = \partial / \partial x_k$:
\begin{align}
\DeclareMathOperator{grad}{grad}
(\grad q(x) )_k &= \partial_k q(x) \\
&= 
\partial_k \left( 
\sum_{i,j} a_{ij} x_i x_j + \sum_i b_i x_i + c 
\right) \\
&=
\sum_{i,j} a_{ij} 
\left( 
(\partial_k  x_i) x_j + x_i (\partial_k x_j) \right) + 
\sum_i b_i  \partial_k  x_i\\
&=
\sum_{i,j} a_{ij} 
\left( 
\delta_{ki} x_j + x_i \delta_{kj} \right) + 
\sum_i b_i  \delta_{ki} \\
&=
\sum_j a_{kj} x_j + \sum_i a_{ik} x_i + b_k \\
&=
e_k^\top (A x + A^\top x + b) \\
\end{align}
Which means
$$
\grad q(x) = (A + A^\top) x + b
$$
If $A$ is symmetric ($A = A^\top$) the term can be further simplified to
$$
\grad q(x)
=
2 A x + b \\
$$
which pretty much corresponds to the one dimensional case $ax^2 + bx + c \mapsto 2 ax + b$.
A: If you understand what a gradient is and are simply looking for a quick reference, you can find the formula in The Matrix Cookbook (equation 97 on page 12), it has useful relationships so you don't have to re-derive them if you forget them.
Just to review: 
$q(\boldsymbol{x})$ is a real valued function and its gradient will be a vector of the same length as $\boldsymbol{x}$. The $i$th entry of the gradient vector is the derivative of $q(\boldsymbol{x})$ with respect to the $i$th entry of $\boldsymbol{x}$. Therefore, since $c$ is just a constant (and because the derivative of a finite sum is the sum of the derivatives) it doesn't affect the gradient of $q(\boldsymbol{x})$ and can be ignored. You can then "pretend" that $c=0$ and use the formula I mentioned as a reference for your calculations.
A: $$q(x+h)=(x+h)^TA(x+h)+b^T(x+h)+c=\\=x^TAx+b^Tx+c+\color{blue}{h^TAx}+x^TAh+b^Th+h^TAh=\\ =\color{red}{x^TAx+b^Tx+c}+\color{blue}{x^TA^Th}+x^TAh+b^Th+\color{brown}{h^TAh}=\\=\color{red}{q(x)}+x^T(A^T+A)h+b^Th+\color{brown}{O(\lVert h\rVert^2)}$$
Hence, $$\nabla_xq=x^T(A^T+A)+b^T$$
