Is this condition sufficient to ensure the locally convexity of a function at a given point? Given $\bar x\in \mathbb R^n$. Let $f:\; \mathbb R^n\to \mathbb R$ be a nonconvex continuous function on $\mathbb R^n$ satisfying the followings
(i) $f$ is not differentiable at $\bar x$,
(ii) There exists an open subset $U\subset \mathbb R^n$ such that $f$ is twice continuously differentiable on $U\setminus \{\bar x\}$ and $\nabla^2 f(x)$ is positive definite for all $x\in U\setminus \{\bar x\}$.
Is it true that $f$ is locally convex at $\bar x$ (more precisely $f$ is convex on $U$)?
Thank you for any help!
 A: Take the function 
$$
f(x) = \min(\ (x-1)^2,\ (x+1)^2 \ ).
$$
It is continuous, twice continuously differentiable outside zero, second derivative is positive definite (when it exists), yet $f$ is not convex.
A: The answer by daw shows clearly, that $f$ might not be convex in case $n = 1$.
However, $f$ has to be convex for $n \ge 2$: Let $x,y \in U$ and $\lambda \in [0,1]$ be given. If $\bar x$ does not lie on the line segment $[x,y]$, then we get
\begin{equation*}
 f( \lambda \, x + (1-\lambda) \, y )
 \le
 \lambda \, f(x) + (1-\lambda) \, f( y )
\end{equation*}
by the usual argument.
Otherwise, choose any unit vector normal to $x-y$.
By the above argument (shift the line segment by $\varepsilon \, n$), we find
\begin{equation*}
 f\big( \lambda \, (x+\varepsilon \, n) + (1-\lambda) \, (y + \varepsilon \, n) \big)
 \le
 \lambda \, f(x + \varepsilon \, n) + (1-\lambda) \, f( y + \varepsilon \, n )
\end{equation*}
for any $\varepsilon$ small enough (such that everything lives in $U$).
Using the continuity, we can pass to the limit $\varepsilon \to 0$ and obtain
\begin{equation*}
 f( \lambda \, x + (1-\lambda) \, y )
 \le
 \lambda \, f(x) + (1-\lambda) \, f( y ).
\end{equation*}
This shows that $f$ is convex for $n \ge 2$.
