Absolute Value Alternative To Piece-Wise Equations

Saturday, August 26, 2017

#S
y(x) = Σ [Sn*|x + Bn|] + S0*x + B0
n=1

Overview

This is my formula designed to turn any set of coordinates into a single absolute value equation that will intercept, and draw a line between, each and every single point. This algorithim eliminates computationaly costly branching when computers use formulas generated by this algorithim.


Interactive Demo

I used javascript to program the following demo which will take any set of any number of coordinates and spit out an absolute value equation that will intercept all the points. Go ahead, type in some coordinates. It won't bite. Also, very important, you can enter in as many coordinates or as few coordinates as you want. This formula can accept 2 coordinates just as well as 2,000 coordinates. To enter in a new coordinate, simply end the line with a comma, put in a starting opening parenthese, put in your x value, put in a comma, put in your y value, and end it with a closing parenthese.

Example #1: 3 coordinates
You can also edit theese boxes to any number of any coordinates you want.
Example #2: 2 coordinates
You can also edit theese boxes to any number of any coordinates you want.
Example #3: 15 coordinates
You can also edit theese boxes to any number of any coordinates you want.
Resulting EquationResulting EquationResulting Equation
 
 
 
Try It Out!
Entering in a value for x into the following equation will generate the corresponding number.
Try It Out!
Entering in a value for x into the following equation will generate the corresponding number.
Try It Out!
Entering in a value for x into the following equation will generate the corresponding number.
y() =  
y() =  
y() =  
Equation Graph
The following chart visually displays what the graph looks like. Special thanks to XY.js
Equation Graph
The following chart visually displays what the graph looks like. Special thanks to XY.js
Equation Graph
The following chart visually displays what the graph looks like. Special thanks to XY.js



The Underlying Math Of This Mathematical Proccedure

The following steps are the same ones used in the demo above which are used to generate the absolute value equation. The example section will demonstrate how you do the steps to help you understand the equation.

Steps Mathematical Represenation Example
Retreive the desired X and Y coordinates in coordinate pairs N/A (x, y) = {(-1, 0), (4, 1), (2, -3)}
Make sure the X and Y coordinate pairs are sorted from first to last. N/A (x, y) = {(-1, 0), (2, -3), (4, 1)}
Create a list of the X coordinates multiplied by -1 from the pairs and store them in list B. Bn = -Xn+1 for #X > n > 1 B = {-2}
Calculate a list of the M slopes of each line. Mn =
Yn+1 - Yn
Xn+1 - Xn
for #X > n > 0
M = {-1, -2}
Calculate the absolute value slopes by averaging the difference in the regular M slopes and put the resulting values in list S. Sn =
Mn+1 - Mn
2
for #M > n > 0
S = {1.5}
Calculate the value of S0. The reason for the third equals sign is just to show you an additional way you can get the same number. S0 = M1 + ΣS = M#M - ΣS Where ΣS is the summation of the other currently known values in list S (1 through #S). S0 = 0.5
To calculate the last unknown, the value of B0, you need to run the rest of the equation on an already known coordinate.
#S
B0 = Y1 - ( Σ [Sn*|X1 + Bn|] + S0*X)
n=1
B0 = -4
Then, to derive the formula, plug the numbers into this summation, then unroll it.
#S
y(x) = Σ [Sn*|x + Bn|] + S0*x + B0
n=1
Where y(x) is the f-of-x equation that will spit out the number interpolated between the two nearest coordinates
y(x) = 1.5*|x - 2*x| + + .5*x - 4

Final Words...

I hope you learned something new on this page reguarding piece-wise calculus. And, I hope you will use it for good in this world. I know I will.