function calculateDecay() {
// Get input values
var n0 = parseFloat(document.getElementById('initialQuantity').value);
var nt = parseFloat(document.getElementById('finalQuantity').value);
var t = parseFloat(document.getElementById('timeElapsed').value);
var errorDiv = document.getElementById('error-message');
var resultDiv = document.getElementById('result-container');
// Reset display
errorDiv.style.display = 'none';
resultDiv.style.display = 'none';
// Validation
if (isNaN(n0) || isNaN(nt) || isNaN(t)) {
errorDiv.innerText = "Please fill in all fields with valid numbers.";
errorDiv.style.display = 'block';
return;
}
if (n0 <= 0) {
errorDiv.innerText = "Initial quantity must be greater than zero.";
errorDiv.style.display = 'block';
return;
}
if (nt <= 0) {
errorDiv.innerText = "Remaining quantity must be greater than zero (quantities approach zero but do not reach it in this model).";
errorDiv.style.display = 'block';
return;
}
if (t = n0) {
errorDiv.innerText = "For exponential decay, the remaining quantity must be less than the initial quantity. If it is larger, this is exponential growth.";
errorDiv.style.display = 'block';
return;
}
// Logic: N(t) = N0 * e^(-lambda * t)
// ln(N(t)/N0) = -lambda * t
// lambda = -ln(N(t)/N0) / t
var ratio = nt / n0;
var lambda = -Math.log(ratio) / t;
// Calculate derived metrics
var halfLife = Math.log(2) / lambda;
var meanLifetime = 1 / lambda;
// Decay percentage per time unit: 1 – e^(-lambda)
var decayPercent = (1 – Math.exp(-lambda)) * 100;
// Display results
document.getElementById('decayConstantResult').innerText = lambda.toPrecision(6);
document.getElementById('decayPercentageResult').innerText = decayPercent.toFixed(4) + "% / time unit";
document.getElementById('halfLifeResult').innerText = halfLife.toFixed(4) + " time units";
document.getElementById('meanLifetimeResult').innerText = meanLifetime.toFixed(4) + " time units";
resultDiv.style.display = 'block';
}
Understanding Exponential Decay
Exponential decay occurs when a quantity decreases at a rate proportional to its current value. This mathematical model is fundamental in various fields, including physics (radioactive decay), finance (depreciation of assets), and pharmacology (drug clearance from the body).
Unlike linear decay, where a fixed amount is lost every time period, exponential decay loses a fixed percentage every time period. This means the process slows down as the quantity decreases, theoretically never reaching absolute zero.
The Exponential Decay Formula
The standard equation used to calculate exponential decay is:
N(t) = N₀e-λt
Where:
N(t): The quantity remaining at time t.
N₀: The initial quantity (at time t=0).
λ (Lambda): The decay constant (a positive number).
t: The time elapsed.
e: Euler's number (approximately 2.71828).
How to Calculate the Decay Rate (λ)
If you know the initial amount, the final amount, and the time that has passed, you can solve for the decay constant λ using natural logarithms:
λ = – ln( N(t) / N₀ ) / t
This calculator performs this specific operation automatically. Once you have lambda, you can easily calculate the Half-Life, which is often more intuitive to understand.
Half-Life Calculation
The half-life ($t_{1/2}$) is the time required for a quantity to reduce to half of its initial value. It is related to the decay constant by the following equation:
Half-Life = ln(2) / λ ≈ 0.693 / λ
Real-World Examples
1. Radioactive Decay
Radioactive isotopes decay into stable isotopes over time. For example, Carbon-14 dating uses the known decay rate of Carbon-14 to estimate the age of organic materials. If you start with 100g of a substance and have 50g left after 5,730 years, the calculator can determine the specific decay constant.
2. Drug Clearance
In pharmacokinetics, the body eliminates drugs at a rate proportional to the concentration in the bloodstream. If a patient takes a 500mg dose, and blood tests show 250mg remaining after 4 hours, the biological half-life is 4 hours.
3. Asset Depreciation
Car values often follow an exponential decay curve rather than a linear one. A new car might lose 15% of its value every year. This "declining balance" method is a form of exponential decay where the value drops sharply initially and then levels off.
Mean Lifetime (τ)
The mean lifetime (tau) represents the average time a particle (or unit of quantity) "survives" before decaying. Mathematically, it is the reciprocal of the decay constant ($\tau = 1 / \lambda$). It is the time at which the quantity has decayed to $1/e$ (approximately 36.8%) of its original value.