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

193 Views Asked by At

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)$

Thanks in advance

2

There are 2 best solutions below

0
On

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.

0
On

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 :

enter image description here

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