I was reading the Wikipedia article about Convex Functions 1. The article states that:
However, a function whose sublevel sets are convex sets may fail to be a convex function.
However, I have trouble imagining a function like this.
Can anyone provide an example of this situation?
Any function who has convex level sets is quasiconvex, which is a weaker notion than convexity. As Victor Hugo pointed out, $f(x)=1-e^{x^2}$ is one such function which is quasiconvex, yet nonconvex.
This graph displays another example. The red function is the quasiconvex function $\min\{1,|\cdot|\}$, the black line shows the level, and the yellow line shows its level set. Since the level set is always an interval, the level set is convex, so our function is quasiconvex. However, this function is nonconvex due to its "kinks" appearing at $\pm 1$.