Say we know a "limit" value A and an "initial increment" B as well as a "target increment" C where C < B << A
Unfortunately I lack the skill to express this mathematically as this comes from a programming task, but hope this makes sense:
Say we continuously loop the following steps until A <= 0:
- we decrease A by B.
- We decrease B in such a way that when this loop ends (aka A <= 0), B is exactly C.
Effectively we decrease A at a steadily slower rate but just fast enough that we do not become slower more than that given minimum B.
Now how do we find by how much to decrease B every step and how many steps will it take? (the one can easily be calculated from the other of course).
Please excuse the sloppy definitions. Am coming to this from a programming problem (wanting to fit a series of visually appealing curves on a line).
Huge thanks in advance!
While not explicitly specified in the question, I am looking for a decrease pattern such that $B$ decreases linearly every iteration. (Alternatively, for example $B$ can be decreased to $C$ anyway in iteration $0$, and still satisfy the given goal)
Let $T$ be the number of steps (to be decided). Let $d$ be the decrease of $B$ per iteration:
$$d = \frac{B_0-C}T$$
The values of $A$ and $B$ at the end of iteration $i-1$, or the respective values at the start of iteration $i$, will be:
$$\begin{align*} B_i &= B_{i-1} -d\\ &= B_0 - id\\ A_i &= A_{i-1} - B_{i-1}\\ &= A_0 - B_0 - B_1 - \cdots - B_{i-1}\\ &= A_0 - iB_0 + 0d + 1d + \cdots + (i-1)d\\ &= A_0 - iB_0 + \frac{(i-1)id}{2} \end{align*}$$
The goal is to have non-positive $A$ at the end of iteration $T-1$:
$$\begin{align*} A_T &\le 0\\ A_0 - TB_0 + \frac{(T-1)Td}{2} &\le 0\\ A_0 - TB_0 + \frac{(T-1)(B_0-C)}{2} &\le 0\\ A_0 + \frac{-TB_0 - TC-B_0+C}2 &\le 0\\ 2A_0 -B_0+C &\le T(B_0+C)\\ T &\ge \frac{2A_0-B_0+C}{B_0+C} \end{align*}$$
So try $d$ depending on $T=\frac{2A_0-B_0+C}{B_0+C}$ (which may be a non-integer).
For example, $A_0=100, B_0 = 20, C = 5$, then
$$\begin{align*} T &= \frac{2\cdot100-20+5}{20+5} = 7.4\\ d &= \frac{20-5}{7.4} = 2.027 \end{align*}$$
$$\begin{array}{c|ll} i\ \text{(iteration)}&A_i\ \text{(starting value)}&B_i\ \text{(starting value)}\\\hline 0&100&20\\ 1&80.000&17.973\\ 2&62.027&15.946\\ 3&46.081&13.919\\ 4&32.162&11.892\\ 5&20.270&9.865\\ 6&10.405&7.838\\ 7&2.568&5.811\\ 8&-3.243&3.784 \end{array}$$
Note how $B_8$ is below $C=5$, but that value is not used for later $A$ and hopefully is unimportant.