Minimizing Area by Approximation Suppose I have an increasing step function $E_c$ given by
$$E_c(\phi) = \sum_{i=1}^n E_i \theta(\phi - \phi_i),$$
where $\theta$ is the Heaviside step function and $E_i$, $\phi$, and $\phi_i$ are all and real and $n$ is a small integer, approximately 6. (Also, $E_i > 0$ and $ 0 < \phi_i \leq 2\pi$.)
I want to find a line such that the area between the line and the step function is minimized. That is, I want to find $m$ and $\phi_0$ to minimize $A$, where
$$A = \int_0^{2\pi} |E_c - m(\phi - \phi_0)|d\phi.$$
Does anyone know whether methods have already been developed to do this? Thanks!

You can formulate the problem as follows
$$\min A \rightarrow \min \bigg(\int_0^{2\pi} \big(E_c - m\phi - k\big)^2d\phi \bigg)$$
and partitioning your domain
$$\min \bigg(\int_0^{\phi_1} \big(- m\phi - k\big)^2d\phi + \int_{\phi_1}^{\phi_2} \big(E_1- m\phi - k\big)^2d\phi +\int_{\phi_2}^{\phi_3} \big(E_1+E_2- m\phi - k\big)^2d\phi+...+\int_{\phi_n}^{2\pi} \big(E_1+E_2+...+E_n- m\phi - k\big)^2d\phi \bigg)$$
By doing the integrations
$$\int_0^{\phi_1} \big(- m\phi - k\big)^2d\phi =k^2\phi_1+km\phi_1^2+\frac{m^2\phi_1^3}3$$
$$\int_{\phi_1}^{\phi_2} \big(E_1- m\phi - k\big)^2d\phi=\frac{(E_1-m\phi_1)^3-(E_1-m\phi_2)^3}{3m}$$
$$\int_{\phi_2}^{\phi_3} \big(E_1+E_2- m\phi - k\big)^2d\phi=\frac{(E_1+E_2-m\phi_2)^3-(E_1+E_2+m\phi_3)^3}{3m}$$
$$...$$
$$\int_{\phi_n}^{2\pi} \big(E_1+E_2+...+E_n- m\phi - k\big)^2d\phi=\frac{(E_1+E_2+...+E_n-m\phi_n)^3-(E_1+E_2+...+E_n+2m\pi)^3}{3m}$$
Now we can take the partial derivatives w.r.t. $m$ and $k$ and solve for minimum value.
