# Ask Uncle Colin: Fitting a Curve

Dear Uncle Colin,

I’m writing a handbook for a game in which a character’s block percentage is a function of the number of defence points they have. I know the following values: | Defence points | Block percentage | |80| 11.7| |280| 31.8| |480| 44.4| |680| 53.1| |880| 59.4| |1080| 64.2| |1280| 68|

I know that similar games use a formula like $B=\frac{120}{120+D}$, but that doesn’t work here! Can you figure out the formula?

- Refine Our Game, Understand Equation

Hi, ROGUE, and thanks for your message!

First up, the formula you have there definitely won’t work – when $D=0$, $B=1$ and when $D$ gets large, $B$ goes to zero – I think you might mean $B=\frac{120D}{120+D}$ , then multiplied by 100 to get a percentage.

Second, generally there isn’t a systematic way to find the One True Formula for a set of points – you could easily come up with a degree-7 polynomial that passes through all of these points, but that wouldn’t be right for other values.

Third, I ought to confess: I found the solution by using a curve fitter, but now I know the answer I can retcon a working process that sounds logical.

### What properties should our formula have?

- Taking a hint from the question, let’s assume we have some sort of rational function – let’s say $B = p + \frac{q}{r+D}$ for some constants $p$, $q$ and $r$. I could put a constant in front of the $B$ as well, but it’s unnecessary – unless it’s zero, I can scale everything in the fraction to get rid of it.
- Presumably we want $B=0$ when $D=0$ and $B\to100$ as $D\to\infty$.

Just using those two pieces of information should allow us to get rid of two constants:

- $0 = p + \frac{q}{r}$
- $100 = p$

So we have $p=100$ and $q = -100r$. That makes our formula $B= 100 - \frac{100r}{r+D}$, or (better yet) $B = \frac{100D}{r+D}$. All we need to do now is find $r$. (Aside: thinking about it, it makes sense to have a factor of $D$ on the top if we want $(0,0)$ as a solution pair.)

The number that jumps out at me from your table is $(480, 44.4)$ – assuming $r$ is a nice number, I’m going to infer that 44.4 is likely to be $\frac{400}{9}$.

So $\frac{400}{9} = \frac{48,000}{480+r}$, which rearranges to $(400)(480) + 400r = (48,000)(9)$

Dividing it all by 400 gives $480 + r = 120 \times 9$, so $r = 120 \times 5 = 600$. Hey look! It *is* a nice number! The formula is $B=\frac{100D}{600+D}$.

We can check this with, say, $D=1080$: it should give $\frac{1080\times 100}{600 + 1080}$, which has a factor of 60 top and bottom, making $\frac{1,800}{28}$ or $\frac{450}{7}$. That works out to 64 and two sevenths, which is (allowing for truncation rather than rounding) spot on.

Hope that helps!

- Uncle Colin