## Problem [[images/f1.png]] ## Solution Let the 2 known points be A and B. To solve for a and b for point A: [[images/f2.png]] Substitution of `b` into original eqn for point B: [[images/f3.png]] To find `b`, substitute `a` back into the equation for `b` ### Checking Using the following input as sample: ``` {stops=32, distance=39.081000 km, time=66.000000 min} {stops=31, distance=36.573000 km, time=62.000000 min} ``` Answer should be: ``` a = speed = 0.66411... b = stopTime = 0.2235337... ``` ### Error Handling If any of the 2 data points return "null", only one data point can be used. To handle this, the stopTime (b) is assumed to be a default value. [[images/f4.png]] ## Coding ### Final Equations [[images/f5.png]] ### Optimization To optimize calculations, number of divisions should be decreased. This is because based on [Intel's arithmetic latencies](https://www.agner.org/optimize/instruction_tables.pdf#page=63). The following equations and corresponding pseudocode is proposed. [[images/f6.png]] In the pseudocode, `speed` refers to the mathematical constant `a` while `stopTime` refers to the constant `b`. `a` and `b` refer to the 2 data points. ``` sRatio = b.stops / a.stops speed = (b.distance - sRatio*a.distance)/(b.time - sRatio*a.time) stopTime = (a.time*speed - a.distance)/(a.stops * speed) ```