# Tricky algebra / algorithm, anyone?

**URL:** <https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292>\
**Category:** Factual Questions\
**Created:** [January 8, 2014, 6:26pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292 "2014-01-08T18:26:17Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrokenBriton](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BrokenBriton](https://boards.straightdope.com/u/BrokenBriton)\
**Post date:** [January 8, 2014, 6:26pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/1 "2014-01-08T18:26:17Z")

</div>

I am trying to understand the pricing model of a cab firm from looking at quotes generated on their app. They charge like this; there is a minimum fare for a set number of miles (say £12.00 for 3 miles), and after that a flat rate per mile (say £2.00 per mile thereafter). That must mean there are three unknown variables:

Minimum Fare: x  
Number of miles: y  
Price per mile thereafter: z

What I do have, though, is a couple of quotes:

Where the journey distance is 7 miles, the quoted fare is £18.29  
Where the journey distance is 22 miles and the quoted fare is £35.49

I did think more than two quotes might be needed, but maybe it’s not even possible given the fact of three variables.

Anyway, I’d be very grateful for any thoughts. Cheers.

---

<div class="post-metadata">

**Author:** ![KneadToKnow](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kneadtoknow/32/3999_2.png) [@KneadToKnow](https://boards.straightdope.com/u/KneadToKnow)\
**Post date:** [January 8, 2014, 6:28pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/2 "2014-01-08T18:28:22Z")

</div>

There might be a fourth variable, “surcharge for distances we really don’t want to travel and are willing to price ourselves out of.”

---

<div class="post-metadata">

**Author:** ![Keeve](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@Keeve](https://boards.straightdope.com/u/Keeve)\
**Post date:** [January 8, 2014, 6:38pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/3 "2014-01-08T18:38:29Z")

</div>

Can’t be done with this info. Also need the number of miles for the fixed minimum after that, all you need is EITHER of those two examples. (OR, if you had a third example, that would work too, I think.)

---

<div class="post-metadata">

**Author:** ![leahcim](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@leahcim](https://boards.straightdope.com/u/leahcim)\
**Post date:** [January 8, 2014, 6:39pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/4 "2014-01-08T18:39:20Z")

</div>

It is definitely underdetermined with just those two quotes. Assuming y \< 7, any number of quotes for trips 7 miles or longer will be insufficient to determine what y and x are exactly.

Basically the pricing scheme has a flat region and a non-flat linear region, and you need two quotes from the non-flat region, and one from the flat region to make the determination (at least assuming the pricing is continuous).

---

<div class="post-metadata">

**Author:** ![Thudlow\_Boink](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/thudlow_boink/32/320_2.png) [@Thudlow\_Boink](https://boards.straightdope.com/u/Thudlow_Boink)\
**Post date:** [January 8, 2014, 6:41pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/5 "2014-01-08T18:41:56Z")

</div>

If I understand correctly, the OP’s situation yields the following two equations:  
x + (7-y)z = 18.29, or x + 7z - yz = 18.29  
x + (22-y)z = 35.49, or x + 22 - yz = 35.49

By subtracting one from another, we can eliminate the x and the yz terms, and get  
15z = 17.20

but this would yield a fractional value for z (1.146666…)

---

<div class="post-metadata">

**Author:** ![BrokenBriton](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BrokenBriton](https://boards.straightdope.com/u/BrokenBriton)\
**Post date:** [January 8, 2014, 6:58pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/6 "2014-01-08T18:58:44Z")

</div>

Hi guys - great response! Thanks. I can do more quotes 😃

**Maybe one of the earlier quotes was wrong** - these are correct:

5 miles 14.39  
7 miles 18.29  
13 miles 29.99  
22 miles 47.54

Thanks again for the great response!

Fwiw, my instinct was it might be one of those ‘black box’, 10,000 iterations-type thing …

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)\
**Post date:** [January 8, 2014, 7:03pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/7 "2014-01-08T19:03:42Z")

</div>

Looks like those four match:

4.64 + (1.95 \* miles)

---

<div class="post-metadata">

**Author:** ![BrokenBriton](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BrokenBriton](https://boards.straightdope.com/u/BrokenBriton)\
**Post date:** [January 8, 2014, 7:10pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/8 "2014-01-08T19:10:50Z")

</div>

> [@chrisk](#):
>
> Looks like those four match:
> 
> 4.64 + (1.95 \* miles)

Hi chrisk, forgive me for quoting myself here:

> [@](#):
>
> Minimum Fare: x  
> Number of miles: y  
> Price per mile thereafter: z

I presume 1.95 would represent z ?

I’m no shakes at this, how does 4.64 break down?

---

<div class="post-metadata">

**Author:** ![Crotalus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/crotalus/32/41_2.png) [@Crotalus](https://boards.straightdope.com/u/Crotalus)\
**Post date:** [January 8, 2014, 7:17pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/9 "2014-01-08T19:17:50Z")

</div>

He’s saying 4.64 is the minimum x, 1.95 is the per mile charge z. The slight twist here is that there is no small amount of travel that you get for 4.64, that is the charge for zero distance. All travel is charged at 1.95 per mile plus the fixed fee of 4.64.

So the formula is X + (Y\*Z) or Fare = 4.64 + (1.95 \* Y).

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)\
**Post date:** [January 8, 2014, 7:19pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/10 "2014-01-08T19:19:48Z")

</div>

Still not enough information to establish y, since we don’t see two trips that are at the same price, or that don’t fit on the same slope. x could be 4.64 for a y of 0, or y could be any value up to 5, and then you’d raise x by (1.95 \* y)

Does that help?

(Basically what **Crotalus** just said.)

---

<div class="post-metadata">

**Author:** ![BrokenBriton](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BrokenBriton](https://boards.straightdope.com/u/BrokenBriton)\
**Post date:** [January 8, 2014, 7:25pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/11 "2014-01-08T19:25:35Z")

</div>

Thank you everyone who piped up earlier, and thatk you **Crotalus** for your explanation.

**chrisk** - as far as I’m concerned, you should get the Nobel prize! I guess I was maybe asking for the impossible and what you have offered is really so helpful. Thanks.

On a varitaion of the modern theme, is there a formula for that? 😉

eta: sorry, I see **Crotalus** has added a formula. Cheers.

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)\
**Post date:** [January 8, 2014, 7:44pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/12 "2014-01-08T19:44:27Z")

</div>

Hehe.

I just plotted the numbers you gave me in an Excel graph, noticed that they formed a straight line, and solved the linear equation.

---

<div class="post-metadata">

**Author:** ![BrokenBriton](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BrokenBriton](https://boards.straightdope.com/u/BrokenBriton)\
**Post date:** [January 8, 2014, 7:48pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/13 "2014-01-08T19:48:56Z")

</div>

I’m guessing that means you solved what you already had?

---

<div class="post-metadata">

**Author:** ![BrokenBriton](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BrokenBriton](https://boards.straightdope.com/u/BrokenBriton)\
**Post date:** [January 8, 2014, 8:40pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/14 "2014-01-08T20:40:43Z")

</div>

I’ve been staring at this on a speadsheet and the magic connection has come yet …

> [@](#):
>
> X + (Y\*Z) or Fare = 4.64 + (1.95 \* Y)

okay, with the information I have : £14.39 = X + (Z \* 5)

… I don’t know how to plug this into Excel with two variables. Could you help one step further?

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)\
**Post date:** [January 8, 2014, 10:53pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/15 "2014-01-08T22:53:42Z")

</div>

> [@BrokenBriton](#):
>
> I’ve been staring at this on a speadsheet and the magic connection has come yet …
> 
> okay, with the information I have : £14.39 = X + (Z \* 5)
> 
> … I don’t know how to plug this into Excel with two variables. Could you help one step further?

Okay, I’ll take you through my entire process in Excel, as best I can remember it, including the graph, which was the important bit.

First, I typed in all four pairs of values, miles in column A, pounds in column B:

```auto

A	B
5	14.39
7	18.29
13	29.99
22	47.54

```

Then I highlighted the entire block, chose Insert, Chart, X-Y (Scatter), and just finished with the default options from there. That shows the graph of the four trips, with cost up the left axis, miles along the bottom axis, and shows that they all fall along a fairly straight, diagonal line, which intersected the left axis.

From there, I went into the next column, cell C2, and typed in =A2-A1 as a formula. Copied this formula two cells down and one cell to the right. So now column C shows the difference in miles between adjacent trips, and column D shows the difference in price. Finally, in E2, I entered = D2/C2, and copied that down to row 4. So column E shows the ratio of marginal price over marginal distance. If I was right that the line on the graph was straight, the values in column E would be constant, and they are, at 1.95 – that’s our cost per additional mile.

Then I probably went down to A6, typed in =1.95 \* 5 to see how much the cost for 5 miles would be at 1.95 a mile, and then punched = b1-a6 into cell B2 to see how much higher the total for the 5 mile trip was. That gave me the fixed fee of 4.64 for a 0 mile trip

```auto

A	B	C	D	E
5	14.39			
7	18.29	2	3.9	1.95
13	29.99	6	11.7	1.95
22	47.54	9	17.55	1.95

9.75	4.64			

```

This isn’t the proper way to solve a linear equation, it just seemed to make sense as I was doing it. 😉

---

<div class="post-metadata">

**Author:** ![BrokenBriton](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BrokenBriton](https://boards.straightdope.com/u/BrokenBriton)\
**Post date:** [January 8, 2014, 11:22pm UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/16 "2014-01-08T23:22:56Z")

</div>

Okay, that was great of you to take the time.

I should mention you probably meant B6 when you said B2 here, but I’m only mentioning that for anyone following …

> [@](#):
>
> and then punched = b1-a6 into cell B2

This will take me a while to digest but (a) it’s seriously impressive and (b) it does highlight (graphically) the mystery of \<5.

Thanks again.

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)\
**Post date:** [January 9, 2014, 2:03am UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/17 "2014-01-09T02:03:22Z")

</div>

> [@BrokenBriton](#):
>
> I should mention you probably meant B6 when you said B2 here, but I’m only mentioning that for anyone following …
> 
> This will take me a while to digest but (a) it’s seriously impressive and (b) it does highlight (graphically) the mystery of \<5.

Yes, that’s right, I meant B6, but was thinking of the second column, typed a two, and didn’t catch it.

\<5 is definitely mysterious, as I’m not sure what you’re talking about. 😃

---

<div class="post-metadata">

**Author:** ![BrokenBriton](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BrokenBriton](https://boards.straightdope.com/u/BrokenBriton)\
**Post date:** [January 9, 2014, 8:33am UTC](https://boards.straightdope.com/t/tricky-algebra-algorithm-anyone/678292/18 "2014-01-09T08:33:54Z")

</div>

Just that x and y relate to under £5.00 and are not determinable.

z is definitely very cool though 🙂
