TITLE: How do I calculate the gradient of a function in a $n$-dimensional space?
QUESTION [7 upvotes]: $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.

REPLY [18 votes]: $$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$$