Show convexity of the quadratic function

Just to leave the answer for the general case online for future reference. A function is convex if $f(\lambda x + (1-\lambda) y) \leq \lambda f(x) + (1-\lambda) f(y)$ for all $\lambda\in[0,\;1]$.

It suffices to show for a quadratic function $f(x) = x^TQx$. Therefore using the definition of a convex function:

\begin{align} (\lambda x + (1-\lambda) y)^TQ(\lambda x + (1-\lambda) y)\leq \lambda x^TQx + (1-\lambda)y^TQy \end{align} Equality holds for $\lambda = 0\;\text{or}\;1$. Therefore consider $\lambda\in(0,1)$. The left hand side simplifies to: \begin{align} \lambda^2x^TQx + (1-\lambda)^2y^TQy + \lambda(1-\lambda)x^TQy + \lambda(1-\lambda)y^TQx\leq \lambda x^TQx + (1-\lambda)y^TQy \end{align} Rearranging the terms and simplifying one obtains: \begin{align} & \lambda(1-\lambda)x^TQx + \lambda(1-\lambda)y^TQy - \lambda(1-\lambda)x^TQy -\lambda(1-\lambda)y^TQx\geq 0 \\ & \Rightarrow x^TQx + y^TQy -x^TQy-y^TQx \geq 0 \\ & \Rightarrow (x-y)^TQ(x-y) \geq 0 \end{align} which is true for positive semi-definite $Q\succeq 0$.


By definition of convex, for any $x,y\in\mathbb R$, we have $$f(\frac{x+y}2)\leq\frac12(f(x)+f(y))$$ Thus it is sufficient to reduce and prove that $$\frac12(x+y)^TA(x+y)\leq x^TAx+y^TAy\\ x^TAy+y^TAx\leq x^TAx+y^TAy$$ Namely $$(x-y)^TA(x-y)\geq0$$ which is directly followed by positive semi-definite.