# Fitting an absolute-value formula to a collection of points in the plane

I need an equation to satisfy the following data points and I can't come up with anything. I believe it needs an absolute value as that changes the slope of the line.

Best yet: $y=2x-|x-4|$

Points are: $(1,1)$; $(2,3)$; $(3,5)$; $(4,7)$; $(5,8)$; $(6,10)$; $(7,11)$; $(8,12)$; $(9,13)$; $(10,14)$; $(11,15)$

## migrated from puzzling.stackexchange.comSep 30 '16 at 1:09

This question came from our site for those who create, solve, and study puzzles.

• I don't think this really qualifies as a puzzle. You might be better off posting this questions on Mathematics SE; I've flagged it to ask the mods to migrate it there. – rand al'thor Sep 29 '16 at 23:43
• Oh yay my boredom is finally relevant desmos.com/calculator/p6nqvyekcl – greenturtle3141 Sep 30 '16 at 0:42

If you meant $(5, 9)$ instead of $(5, 8)$, then $$y = 1.5(x + 1) - 0.5|x - 5|$$ works. Otherwise, \begin{align*} y &= 1.5(x + 1) - 0.5|x - 5| + 0.5\min\bigl(|x - 5| - 1, 0\bigr) \\ &= 1.5(x + 1) - 0.5\bigl(1 + \bigl||x - 5| - 1\bigr|\bigr) \end{align*} hits them all.

It is not clear if the goal is to find a function $y(x)$ which fits EXACTLY, or approximately.

If exactly is required : $$\begin{cases} y=2x-1 &\text{ if } x\leq 4 \\ y=8 &\text{ if } x=5 \\ y=x+4 &\text{ if } x\geq 6 \end{cases} \quad\to\quad y=8+(2x-9)H(4.5-x)+(x-4)H(x-4.5)$$ $H$ is the Heaviside step function.

If the fourth point is $(5,9)$ instead of $(5,8)$ a simpler form is : $$y=\frac{1}{2}(3+3x-|x-5|)$$.

If an approximate fit is wanted :

A usual regression calculus is sufficient, for example with the function $y=ax^2+by+c$. This is a linear regression for $a, b, c$ which leads to : $$a\simeq -0.0711$$ $$b\simeq 2.226$$ $$c\simeq -1.085$$ The graph of the function $y=ax^2+by+c$ is shown :

This was computed with the fourth point $(5,8)$.