Sub topic 6
Building a model from two data points
This chapter assumes you can evaluate expressions with integer and fractional exponents, convert between percents and decimals, and solve simple linear equations. You should also know the form f(x) = a·b^x, where a is the initial value and b is the growth factor.
The problem: two unknowns, two facts
The model f(x) = a·b^x has two unknown numbers, a and b. One data point gives one equation, which is not enough to find both. Two data points give two equations, and that is enough, provided the points are compatible with an exponential model.
Suppose you know that f(x1) = y1 and f(x2) = y2. Then:
- y1 = a·b^x1
- y2 = a·b^x2
Both equations contain a, and the unknown b is inside an exponent. The key step is to divide the second equation by the first, so that a cancels.
Deriving the formulas
Divide the two equations:
y2 / y1 = (a·b^x2) / (a·b^x1) = b^(x2 − x1)
The law of exponents b^m / b^n = b^(m−n) turns the right side into a single power of b. To undo that power, raise both sides to the exponent 1 / (x2 − x1):
b = (y2 / y1)^(1 / (x2 − x1))
Once b is known, return to either original equation and solve for a:
a = y1 / b^x1
The process is: ratio, root, back-substitute, check. The check costs one line and catches arithmetic slips.
Worked example 1: whole-number factor
Fit an exponential function through (1, 6) and (3, 24).
- Ratio: 24 / 6 = 4.
- The x-values are 2 apart, so b = 4^(1/2) = 2.
- a = 6 / 2^1 = 3.
- Model: f(x) = 3·2^x.
- Check: f(3) = 3·8 = 24, which matches the second point.
The same steps in code:
def fit_two_points(x1, y1, x2, y2):
b = (y2 / y1) ** (1 / (x2 - x1))
a = y1 / b ** x1
return a, b
a, b = fit_two_points(1, 6, 3, 24)
print(a, b) # 3.0 2.0Worked example 2: decay
Decay needs no new method. A sample is measured at 80 grams on day 2 and 10 grams on day 5. Find the model.
- Ratio: 10 / 80 = 1/8.
- The x-values are 3 apart, so b = (1/8)^(1/3) = 1/2.
- a = 80 / (1/2)^2 = 80 / (1/4) = 320.
- Model: f(x) = 320·(1/2)^x.
- Check: f(5) = 320 / 32 = 10.
Because b is between 0 and 1, the quantity decays. It halves every day, so b = 0.5 means a 50% loss per day. The value a = 320 is the amount at x = 0, which is before either measurement was taken. It is an extrapolation backward in time.
Worked example 3: a root that is not tidy
A town has 1500 residents in year 2 and 2400 in year 6, with years counted from some starting date.
- Ratio: 2400 / 1500 = 1.6.
- The x-values are 4 apart, so b = 1.6^(1/4) ≈ 1.1247.
- a = 1500 / 1.1247^2 ≈ 1185.86.
- The growth rate is b − 1 ≈ 0.1247, or about 12.47% per year.
Most real data gives roots like this. Use a calculator or code and keep the full precision until the final answer.
import math
def fit_two_points(x1, y1, x2, y2):
if x1 == x2:
raise ValueError("the x-values must differ")
if y1 * y2 <= 0:
raise ValueError("the y-values must be nonzero and share a sign")
b = (y2 / y1) ** (1 / (x2 - x1))
a = y1 / b ** x1
return a, b
a, b = fit_two_points(2, 80, 5, 10)
print(round(a, 6), round(b, 6)) # 320.0 0.5
a, b = fit_two_points(2, 1500, 6, 2400)
print(round(a, 2), round(b, 4)) # 1185.86 1.1247
print(round((b - 1) * 100, 2)) # 12.47
print(math.isclose(a * b ** 6, 2400)) # TrueThe version above adds guards. The next section explains why each one is there.
When the two points allow a model
Not every pair of points can be fitted by f(x) = a·b^x with b > 0. The ratio y2 / y1 equals b^(x2 − x1), and a positive base raised to any real power is positive. That rules out some inputs.
| Situation | Result | What to do |
|---|---|---|
| x1 = x2 | Division by zero in the exponent | Two different inputs are needed. Two readings at the same x do not define a rate. |
| y1 and y2 have opposite signs | The ratio is negative, so no real b exists | An exponential with b > 0 cannot cross zero. Choose a different model. |
| Either y is 0 | The ratio is 0 or undefined | An exponential never reaches 0, so the data is not exponential. |
| y1 = y2 | Ratio is 1, so b = 1 | The model is the constant function f(x) = y1. This is valid but not growth or decay. |
| Both y-values negative | Ratio is positive, so a fit exists with a < 0 | The model is valid. It is a reflected exponential. |
Order and the choice of x-values
The order of the points does not matter. If you swap them, both the ratio and the exponent flip. For (3, 24) and (1, 6), the ratio is 6/24 = 0.25 and the exponent is 1/(1 − 3) = −1/2. Then b = 0.25^(−1/2) = 4^(1/2) = 2, the same result.
When one of the points has x = 0, the work shortens. Since b^0 = 1, the y-value at x = 0 is a directly, and you only need the ratio step. For example, from (0, 500) and (3, 4000), a = 500 and b = (4000/500)^(1/3) = 8^(1/3) = 2.
You choose what x means. If x is measured in months, then b is a per-month factor. If you want a per-year factor, convert the x-values to years first, or raise the monthly factor to the 12th power. Mixing units is a common error. For example, a "5% growth per year" model with x counted in months will be wrong by a large margin.
Interpreting the fitted model
After fitting, translate b into words:
- If b > 1, the quantity grows. The percent growth rate per unit of x is (b − 1) × 100.
- If 0 < b < 1, the quantity decays. The percent decay rate per unit of x is (1 − b) × 100.
For b = 0.75, the quantity loses 25% per unit. For b = 1.1247, it gains about 12.47% per unit.
You can also use the model to answer questions between and beyond the data. Interpolation (finding values between x1 and x2) is generally safe if the process really is exponential. Extrapolation (going beyond the data, or before it as with a) is riskier, because small errors in b grow with distance. Chapter 12 returns to the limits of such predictions.
Two points versus many points
Two points always fit an exponential model exactly when the guards above pass, even if the real process is not exponential. The fit proves nothing about the shape of the data. Before trusting the model, ask these questions:
- Is there a reason to expect a constant percent change per period?
- If you have a third data point, does the model predict it? Compute a·b^x3 and compare with y3.
- Are the two points far enough apart? Measurement noise has less relative effect over a long span than over a short one.
If you have many noisy points, a better technique is to take the logarithm of each y-value. The model ln y = ln a + x·ln b is a straight line in x, so a line fit gives ln b as the slope and ln a as the intercept. A later chapter on logarithms covers the tools for this. For now, a quick check with a third point is enough.
a, b = fit_two_points(1, 6, 3, 24)
predicted = a * b ** 2 # test the model at x = 2
print(round(predicted, 2)) # 12.0If a third reading at x = 2 came back as 12, the model holds. If it came back as 9, the data is not exponential, or the readings contain noise. A linear model would predict (6 + 24) / 2 = 15 at x = 2, so this check also separates exponential from linear change.
Summary of the method
- Write down the two points as (x1, y1) and (x2, y2).
- Check that x1 ≠ x2 and that y1 and y2 are nonzero with the same sign.
- Compute b = (y2 / y1)^(1 / (x2 − x1)).
- Compute a = y1 / b^x1.
- Write f(x) = a·b^x and verify it against both points.
- State the percent rate, with units, from b.
Exercise
Find the exponential function f(x) = a·b^x that passes through (1, 12) and (4, 768). Verify it with both points.
Show answer
The ratio is 768 / 12 = 64 and the x-values are 3 apart, so b = 64^(1/3) = 4. Then a = 12 / 4^1 = 3. The model is f(x) = 3·4^x. Check: f(1) = 3·4 = 12 and f(4) = 3·256 = 768, so both points match.
Exercise
A used machine is valued at $240 now (x = 0) and at $135 two years later (x = 2). Assuming exponential change, find the model and the yearly percent change.
Show answer
Since x = 0 at the first point, a = 240. The ratio is 135 / 240 = 0.5625 and the x-values are 2 apart, so b = 0.5625^(1/2) = 0.75. The model is f(x) = 240·0.75^x. Because b = 0.75, the value decays by 1 − 0.75 = 25% per year. Check: f(2) = 240 × 0.5625 = 135.
Exercise
Someone claims that an exponential function with b > 0 passes through (1, 5) and (2, −10). Explain whether this is possible.
Show answer
It is not possible. The ratio y2 / y1 is −10 / 5 = −2, and b^(x2 − x1) = b^1 = b would have to equal −2. A positive base cannot give a negative value, so no exponential with b > 0 passes through both points.