Creating a mathematical formula to price a taxi booking

1.2k Views Asked by At

I've been asked to create a mathematical formula that will be used to price taxi bookings at a local taxi company.

Current system used:

  • A table is used as a reference

enter image description here

Variables:

  • x is the total number of miles
  • y is every stop made

Conditions:

  • Add £3 for the first 2 miles
  • Add £1 for every extra mile incurred (after two miles)
  • Add 50p extra for every half a mile incurred (after two miles)
  • Add 50p for every stop made (excluding pickup and drop off
  • Round to .50 or .00 once calculated

What I've come up with so far based on the variables and conditions above:

$$ f(x,y)= \begin{cases} 3 + 0.50y & \text{$x \leq 2$}\\ x + 1 + 0.50y & \text{$x > 2$}\\ \end{cases} $$

How I need your help:

  • Is this formula suitable?
  • Can it be improved to factor in an expression that will round the price end result to .50 or .00?
  • Can both parts be combined to get rid of the conditional (or perhaps streamlined further if this is not possible)?
2

There are 2 best solutions below

1
On BEST ANSWER

To round a number $z$ to the nearest multiple of $a$, you can use $\lfloor \frac za+\frac12\rfloor \cdot a$. Hence you can use

$$f(x,y)=\begin{cases}3+0.50y&\text{if $x\le 2$}\\ .50\cdot \bigl(\lfloor 2x+\frac12\rfloor +y+2\bigr)&\text{if $x>2$}\end{cases} $$

1
On

If it is $50p$ for every half mile then the formula is (included max to avoid the use of "if")

$$f(x,y)=3+\frac{\lfloor\max\{2x-4,0\}\rfloor}{2}\cdot 0.50+0.50\cdot y.$$

Note that this answer is adapted to the change included in your comment and doesn't fit with the original table of prizes.