# Approximating a function with a convex function

Let $f:\mathbb{R} \rightarrow \mathbb{R}$ be a continuous, differentiable function. Is there a known algorithm that fits $f$ with $g$, which is an order-$n$ polynomial that is convex, in the least square sense?

-
What do you mean by least square in this context, i.e. what objective are you minimizing? –  Robert Israel Dec 31 '12 at 2:06
I would like to minimize the $l_2$-norm of $(f-g)$ –  tatterdemalion Dec 31 '12 at 2:11
Given the examples below, perhaps you want to restrict the function to a bounded interval? –  user53153 Dec 31 '12 at 4:55
Yes. It would be more interesting if the supports of $f$ and $g$ are bounded intervals. –  tatterdemalion Dec 31 '12 at 5:20

I don't think so. For any convex function $g$, $\|\sin x-g(x)\|_{l_2} = \infty$. Similarly I'm not sure how you would want to fit a convex function to $f(x)=-x^2$.
Locally you can always approximate a function by its convex truncated Taylor series $$f(x_0 + y) \approx f(x_0) + y f'(x_0) + \frac{1}{2}y^2 f''(x_0)$$ provided that $f''(x_0)>0$. The same can be done in higher dimensions at points where the Hessian of $f$ is positive-definite.