# formula for asymptotic graph

I need help with an algorithm involving an asymptotic output.

I'm not a student and this is not homework, but it has been many years since I used to know how to figure this out. This will be used in creating a lookup chart for dice rolling in a RPG I am making. The input, $x$, is the difference between the character's stats (ie. attack skill vs enemy defense).

Acceptable values for $x$ will be positive integers I want to calculate the output, $y$, to generate a graph whose curve is similar to this: graph but whose horizontal asymptote is $y=20$ and vertical asymptote at $x=0$.

I'm guessing there is an exponent somewhere in the formula but I can't figure how to generalize the formula structure. Like $y=x^2$ or whatever.

It would help to know more criteria since there are a lot of possible functions here. The hyperbola has been mentioned. Two more examples with some different behavior are $$y = 20 - 1000\frac{\exp(-\frac{x}{8})}{x}~ (in~ green~ below)\\ y = \frac{20x^{2}+x-10}{x(x+10)}~ (in~ black~ below)$$ The hyperbola solution is in red below.

Basically $y = 20 - \frac{f(x)}{g(x)}$, up to tweaking signs of terms, will work if $g(0) = 0$ and $g$ has no other positive roots, and $\lim_{x\rightarrow +\infty} f(x) = 0$. Within reason you can get a lot of behaviors.

Edit: it appears the OP has some additional slope constraints. Basically every slope constraint requires a new coefficient. Consider the rational function $$R(x) = \frac{Ax^n + a_1x^{n-1} + \cdots - a_n}{x^n + x^{n-1} + \cdots + dx}, \forall i \in [1,n]~ (a_i \geq 0)$$ Only $a_n$ is marked as negative. Note this will match the criteria in the OP: $$\lim_{x\rightarrow +\infty}R(x) = A \\ \lim_{x\rightarrow 0^+}R(x) = -\infty$$ The derivative of $R(x)$ is relatively straightforward. Each variable we choose to be non-zero will allow us to specify a different slope at a different point; for instance, if we demand that $R'(1) = 1$ and we set $a_n=2$ then we can determine $d$ algebraically. If we instead demand only that $R'(1) \approx 1$ this gives us some more wiggle room to pick "nice" numbers. But in any case additional constraints require additional coefficients and as more conditions are added the exponent will start to rise in order to give us additional coefficients needed to fit our slope parameters.

But since we can always introduce more variables and higher exponents, we can always solve the system of equations demanded by all the required slopes.

• good point @law-of-fives. I guess one criteria that I want is that for positive x values near 0, what I actually want is a line of slope=1 – ken May 3 '17 at 18:21
• @ken It can't both diverge to $-\infty$ and have a slope of 1. Do you mean something like it has a slope of 1 at $x=1$ or $x=2$ or something similar? – law-of-fives May 3 '17 at 18:48
• exactly, I want slope = 1 at x=1 – ken May 3 '17 at 19:20
• @ken you can try the numerator to be $20x^2-2$ and the denominator to be $x^2+20x$. At one, the slope is $1+\frac{1}{147}$. – law-of-fives May 3 '17 at 19:24
• yes - that looks good - thanks @law-of-fives – ken May 3 '17 at 19:36

Something like $$y = -\frac{20(10-x)}{x}$$ will give you a vertical asymptote at $x=0$, a horizontal asymptote at $y=20$, and an $x$-intercept at $(10,0)$. Take a look at this graph to see what different sorts of graphs you would get from changing the $x$-intercept, and what outputs you would get at various positive integers.

• awesome! Thanks @DMcMor! Using that tool I was able to tweak it a bit more to what I'm looking for, and I'm getting close with: f\left(x\right)=10-\frac{9\left(a-x\right)}{x} – ken May 3 '17 at 17:37
• if possible I would like to "round the edge" a bit more around the low values of y (like y in 2 to 5 range) – ken May 3 '17 at 17:39
• see the picture here goldensword.dimensionfold.com/img/finetune.png I love the green part but would like the yellow part to "come down" a bit – ken May 3 '17 at 17:45