# a closed-form for mean/integral, but weighting positive differences between values and “mean” differently from negative differences?

Given a curve $f(x)$ (for $x \in [0,1]$), and a line $y=a$, let $U$ be the total area below $f$ and above $a$, and let $L$ be the total area above $f$ and below $a$. If $L=U$, this means that $a =\int_0^1 f(x) dx$.

Or if $f(x)$ is a sequence of $n$ numbers, this means $a$ is their mean. Equivalently, $U = \int_0^1 \max(f(x)-a,0) \; dx$, $L = \int_0^1 \max(a-f(x),0) \; dx$.

What I want instead is the value $a$ for which $c \cdot L = U$, for some constant $c>0$.

This can be computed approximately by binary search or exactly with a more cumbersome algorithm, but: is there a closed-form expression for this value? And: has this value been studied?

-
Why do you ask? Does this question come from somewhere? –  Igor Rivin Aug 9 '11 at 15:55
From a battery-charging problem, where $a$ is the constant level of energy available, and $f$ is the energy usage at each moment. So $L$ corresponds to charging into the battery, and $U$ corresponds to discharging from the battery. Because of charge/discharge inefficiencies, after charging 1 unit in, you'll only be able to discharge, say, .5 units out. (For this interpretation to make sense, you might assume $f$ is monotonically increasing.) –  matt j Aug 9 '11 at 19:20
You can't provide any further information about $f$? That would help greatly for a "closed form"... –  J. M. Aug 14 '11 at 17:48
@J.M.: $f$ can just be a step function of with $n$ unit-width steps. –  matt j Aug 15 '11 at 9:50

## 1 Answer

I can't give you a closed form, but maybe rewrite it in a more useful form.

First denote by $A$ the total area $A=\int_0^1 f(x)\;\mathrm{d}x$. Note that $U-L=A-a$.

Then your question is equivalent to solve $(c-1)L=A-a$ for $a$. In the case where $f$ is strictly monotone with inverse $f^{-1}$ and normalized such that $f(0)=0$, we have that $$L = a f^{-1}(a) - F(f^{-1}(a)) ,$$ where $F$ is the antiderivatve of $f$. Setting $a=f(y)$ we obtain that $$L(y) = yf(y) - F(y).$$ Note that $$L'(y) = y f'(y) >0 \qquad\text{for } y\in (0,1) .$$ And hence we have to solve the following equation for $y$ $$A = (c-1)L(y) + f(y) = (c-1)\int_0^y x f'(x)\;\mathrm{d}{x} + f(y) = \int_0^y [(c-1)x+1]f'(x)\;\mathrm{d}{x}$$ and set afterwards $a=f(y)$. In the case $c=1$, this simplifies to the known formula $f(y)=A$ and hence $a=\int_0^1 f(x)\;\mathrm{d}{x}$.

-
Why should it be that $L+U = \int_0^1 f(x) dx$? If $f(x)=10$ and $c=1$, for example, then $L=U=0$ but $\int_0^1 f(x) dx=10$. –  matt j Aug 15 '11 at 9:49
I'm sorry. I misread your question. My post answers not your question. –  André Schlichting Aug 15 '11 at 11:37
I have rewritten my answer in the context of the question. It is maybe not really helpful, but at least should be more correct now. –  André Schlichting Aug 15 '11 at 12:10