Local maximality implies global maximality? 
Let $S$ be the unit sphere in $\mathbb R^n.$ For a given $A\in\operatorname{M}_n(\mathbb R),$ define $f:\mathbb R^n\mapsto\mathbb R$ as $f(x)=\langle x,Ax\rangle.$
  Suppose $a\in S$ is an element such that $\exists \delta\gt0,$ with $f(a)\ge f(x), \forall x\in\mathbb R^n$ such that $\|x-a\|\lt\delta.$ Then is it true that $f(a)\ge f(x), \forall x\in S?$   

Intuitively, I think this must fail, as we are only given a local maximiser. However, I failed to find a counter-example, nor a proof.
If I can calculate the derivative of $f,$ maybe I can conclude that $f$ has no more than one local maximiser, which thus must be a global maximiser. But I do not know about $f'$, either.
Thanks very much in advance for any hint or reference.
 A: I am assuming that $S = \{x | \|x\|=1\}$ and that $a$ is such that $f(a) \ge f(x)$ for all $x \in B(a,\delta) \cap S$, where $\delta >0$. Then $f$ is a global maximizer on $S$.
Since $\langle x, Ax \rangle = \langle Ax , x\rangle = \langle x, A^Tx \rangle = \langle x, {1 \over 2} (A+A^T)x \rangle$, we may assume that $A$ is symmetric, hence orthogonally diagonalizable. In particular, we may assume $f(x) = \sum_k \lambda_k x_k^2$, where the $ \lambda_k$ are real.
Suppose $x$ is such that $x_i \neq 0$ and there is some $\lambda_j > \lambda_i$. Write $(x_i,x_j) = r (\cos \theta, \sin \theta)$, where $r = \sqrt{x_i^2 + x_j^2}$. Note that $\cos \theta \neq 0$ and hence $|\sin \theta| \neq 1$.
We have
\begin{eqnarray}
f(x) &=&\sum_{k \notin \{i,j\}} \lambda_k x_k^2 + \lambda_i x_i^2+ \lambda_j x_j^2 \\
&=&  \sum_{k \notin \{i,j\}} \lambda_k x_k^2 + r(\lambda_i \cos^2 \theta + \lambda_i \sin^2 \theta) \\
&=&  \sum_{k \notin \{i,j\}} \lambda_k x_k^2 + r(\lambda_i + (\lambda_j- \lambda_i) \sin^2 \theta)
\end{eqnarray}
Consequently we can find some $\theta'$ arbitrarily close to $\theta$ such that
$f(x') > f(x)$, where $x'$ is the same as $x$ except with $x_i,y_i$ replaced by $r (\cos \theta', \sin \theta')$, and $\|x'\|=\|x\| = 1$.
Consequently, if $a$ is a local maximizer of $f$, $a$ must be a unit eigenvector corresponding to the maximum eigenvalue $\lambda_\max$. Then it follows that $f(a) = \lambda_\max $, and since $f(x) \le \lambda_\max$ whenever $x \in S$, it follows that $f(x) \le f(a)$ for all $x \in S$.
