For example, imagine an object that consists to equal parts of two substances with the following half-lifes:
- $t_{1, 1/2} = 1d$
- $t_{2, 1/2} = 1000d$
I would now like to find out the time after the object has decayed by half. For this I have this formula: $$ N(t) = \frac{2^{-\frac{t}{t_{1,1/2}}} + 2^{-\frac{t}{t_{2,1/2}}}}{2} = 1/2 $$
Unfortunately, rearranging according to $t$ is not possible, because $log_2(a+b) \neq log_2(a) + log_2(b)$.
Therefore, the only thing that has occurred to me so far is to use this method to calculate the time (code in python):
def average(halfLifes, t):
sum = 0.0
for halfLife in halfLifes:
sum += pow(2, -t / halfLife)
return sum / len(halfLifes);
t = 0
halfLifes = [1, 1000]
stepSize = 4
error = 1
while error > 0.0001:
y = average(halfLifes, t)
if y < 0.5:
t -= stepSize
stepSize /= 2
t += stepSize
else:
t += stepSize
error = abs(y - 0.5)
print("t: " + str(t))
print("y: " + str(average(halfLifes, t)))
This gives the result $t \approx 7.625d$. Unfortunately, the calculation is very slow and for example with 20000 values, the calculation already takes ~9 seconds.
Is there a way to make this faster or to solve this mathematically better? It is not important that the solution is accurate.
Let $x=2^{-t/t_{1,1/2}}$ to produce a sorta polynomial equation instead of an exponential equation. This will be much nicer to solve and probably much more stable. You can also guarantee fast convergence by bracketing the root over $x\in(0,1)$ and using methods such as Brent's method or the Newt-safe method.