Suppose I have a continuous differentiable function $f:\mathbb{R}\rightarrow\mathbb{R}^+$ such that $\int_{\mathbb{R}}f(x)dx<\infty$.
Let's assume the function to be convex and increasing.
Now, for an $x_1$ and $x_2$, I would like to substitute $f(x)$ with a linear function $l(x)=\alpha+\beta x$ such that the area under the curve for the interval $(x_1,x_2]$ remains the same. Mathematically,$$\int_{x_1}^{x_2}f(x)dx=\int_{x_1}^{x_2}l(x)dx$$
Now, how can I find the values of $\alpha$ and $\beta$ that would minimise the total deviation of $l(x)$ form $f(x)$?
In other words, I would like to find $\alpha$ and $\beta$ that minimises $$\int_{x_1}^{x_2}\{f(x)-l(x)\}^2dx,$$the area shaded purple in image 3.