I've decided to open a new, more common question about the simplest function f(1)=-1; f(2)=0; f(3)=1; f(4)=0..
So, here is the question. Let's say we have some function $y=f(x)$ we'd like to find by its values and some restrictions:
- we have pairs
(x0,y0), (x1,y1), .., (xn, yn). - we want to find the function
fthat goes through the points above, but - it should be the combination of the functions +, -, * and several abs.
Is it possible for any pairs? What's the common formula then?
Thank you.
Example: For the pairs $(-10, -3), (-5,-3), (0, 7), (25, 13)$ the function $f(x)= −|x−3| + 5 + |x+5|$ looks good (If I didn't make a typo).
P.S. The shorter function - the better.
Thank you.
P.P.S. Please no polynomials. Only the sum of abs of the |ai*xi+bi|.
If you allow arbitrary numbers appear as coefficients, then the answer is yes. WOLOG, assume your pairs are given in sorted order of $x_i$. i.e.
$$x_0 < x_1 < x_2 < \cdots < x_n.$$ Let $\theta(x)$ be the function $|x| + x$ and define $f(x)$ as
$$\begin{align} f(x) &= y_0 + \sum_{k=1}^n \frac{y_k-y_{k-1}}{2(x_k-x_{k-1})}\left(\theta(x-x_{k-1}) - \theta(x-x_{k})\right)\\ &= y_0 + \sum_{k=1}^n \frac{y_k-y_{k-1}}{2(x_k-x_{k-1})}\left(|x-x_{k-1}| - |x-x_{k}| + ( x_{k} - x_{k-1})\right)\\ &= \frac{y_0+y_n}{2} + \sum_{k=1}^n \frac{y_k-y_{k-1}}{2(x_k-x_{k-1})}\left(|x-x_{k-1}| - |x-x_{k}|\right) \end{align}$$ For any $0 < p < n$, we have
$$\begin{align}f(x_p) = & \frac{y_0+y_n}{2} + \sum_{k=1}^p \frac{y_k-y_{k-1}}{2(x_k-x_{k-1})}\left((x_p-x_{k-1}) - (x_p-x_{k})\right)\\ &\hspace0.7in + \sum_{k=p+1}^n \frac{y_k-y_{k-1}}{2(x_k-x_{k-1})}\left((x_{k-1}-x_p) - (x_{k}-x_p)\right)\\ = &\frac{y_0+y_n}{2} + \sum_{k=1}^p \frac{y_k-y_{k-1}}{2(x_k-x_{k-1})}\left(x_k-x_{k-1}\right) + \sum_{k=p+1}^n \frac{y_k-y_{k-1}}{2(x_k-x_{k-1})}\left(x_{k-1}-x_{k}\right)\\ = &\frac{y_0+y_n}{2} + \frac{y_p - y_0}{2} + \frac{y_p - y_n}{2}\\ = & y_p \end{align}$$ Similarly, one has $f(x_0) = y_0$ and $f(x_n) = y_n$. In short, $f(x)$ is a piecewise linear function passing through all the $(x_k,y_k)$.