Exponentially decaying distribution function

113 Views Asked by At

I don't really know what to call this problem. I need this is for one of my projects. It will be programmed in javascript so edge cases can be handled. I'll try to frame this like a textbook question.

If this is not possible, anything close to this behaviour will work too.

Problem:

I have a fixed number of some item, apples for example, that cannot exist in a broken state (i.e. must be integers). I need to giveaway these apples to villagers in an exponentially decaying fashion at certain intervals (fixed integer) before a fixed end time. The number of apples given on the first distribution will be pre-defined. There should be no apples left after the end time.

Given (user defined) parameters:

$X =$ Total number of apples

$A =$ Number of apples on first distribution

$I =$ Time interval (integer)

$T =$ Total time for distribution (integer)

The end time will be a multiple of time interval, so $T = iI$ of which, either $I$ and $i$ are given or $I$ and $T$.

I need a function $f(x)$ that returns an integer $f(nI)$ (where $n$ is an integer). The domain of time is $(0 \le t \le T)$

so the results should be

$y(0) = A$

$y(T+) = 0$


$y(0I) + y(1I) + y(2I) + ... + y(iI) = X$

$OR$

$A + y(1I) + y(2I) + ... + y(T) = X$

Graph should look something like this: desmos, image

(note: this is not a perfect example as the values are not integers and don't add up to $X$)

My progress so far:

I have tried using the typical half- life based exponential decay functions but couldn't get the desired output

2

There are 2 best solutions below

1
On

Repeated division by an integer and taking the quotient would give you what you need. Terminate when quotient is less than divisor.

Eg:

$$\array { dividend & divisor & quotient & remainder \\ \hline 1000 & 7 & 142 & 6 \\ 142 & 7 & 20 & 2 \\ 20 & 7 & 2 & 6 }$$

The sequence of quotients will have exponential falloff. You can get different types of sequences with different divisors. For eg: try $2$ for the longest possible sequence (using integer division).

The length of sequence is dependent on the initial dividend and the divisor:

$$length = \lfloor \log_{divisor} (dividend) \rfloor$$

The sequence

$$2 \times 7^3, 6 \times 7^2, 2 \times 7^1, 6 \times 7^0 = 686, 294, 14, 6$$

will also give you exponential decay, and will sum up to the dividend (1000 in this case).

This comes from the base-$r$ representation of an integer.

// lambda function for integer division and remainder
let DivRem = (dividend, divisor) => {
    let remainder = dividend % divisor;
    return [(dividend - remainder)/divisor, remainder];
}

// print the integers with exponential falloff (prints in reverse)
// if you need them in reverse order, collect them in an array and reverse them
let initialValue = 1000;
let divisor = 7;
let qr = DivRem(initialValue, divisor);
let multiplier = 1;
while(qr[0] > 0) {
    console.log(qr[1]*multiplier);
    qr = DivRem(qr[0], divisor);
    multiplier *= divisor;
}

If you are given $X:$ total number of objects and $A:$ total initial distribution, what do you think is the first quotient and remainder? What is the first divisor? Hint: $divisor = \lfloor {X \over A} \rfloor$.

But we are also given $T:$ total time for distribution and $I:$ time interval for distribution, so you can compute $n = \lceil {T \over I} \rceil$ to get the number of intervals. This means the

$$balance = initial value - initial distribution$$

needs to be distributed over $n$ intervals. So,

$$divisor = {balance \over n}$$

Then use the algorithm using $balance, divisor$ as parameters.

0
On

After trying @vvgiri's and @md2perpe's suggestions I still couldn't figure out how to do this as intended. So I just removed the requirement for user to define $T$ and calculate it based on other parameters. And the way I've done it allows no way for all of the parameters to be user defined simultaneously.

My current solution: $f(x)$ returns the numbers of apples to distribute at a given time.

$$f(x) = \lfloor A-\frac{xA}{T} \rfloor$$

$$X = \sum_{n=0}^{\frac{T}{I}} f(nI)$$

for more context, you can refer to the actual project, which is now public: maximousblk/astatine

desmos: https://www.desmos.com/calculator/05ofbspddf

same method for exponential decay: https://www.desmos.com/calculator/mvcfqcvtwp

I'm leaving this question unanswered in hope for a better answer where all four of the parameters can be user defined.