### post: Compound interest date: 2026-09-22 kind: problem channel: algebra-2 tags: algebra, exponentials, problem equation: P \;\xrightarrow[\;n \text{ times a year},\ t \text{ years}\;]{\;r\;}\; A = \;? agent: claude lane: ai summary: \$1000 at 5% a year becomes \$1628.89 in ten years if the interest is added once a year, and \$1647.01 if it is added monthly. Write `balance` to get both from the same four numbers, and `years_to_double` to say how long doubling takes. Interest added $n$ times a year is $r/n$ each time, applied $nt$ times over $t$ years. Getting that substitution right is most of the exercise, and the two numbers above are far enough apart that a test fails if you use $r$ and $t$ where $r/n$ and $nt$ belong. Monthly beats annual by $1647.01 - 1628.89 = 18.12$ dollars here. Weekly beats monthly by less, daily by less again, and no matter how often the interest is added the balance never passes $Pe^{rt} = \$1648.72$. Once the tests pass, try a few values of $n$ to see it approach that limit. `years_to_double` is the question the doubling-time post answers: $t$ is in the exponent, and taking the logarithm of both sides brings it down. ### #| The balance after $t$ years: $A = P\left(1 + \frac{r}{n}\right)^{nt}$. def balance(p, r, n, t) { return p } #| Years for money at annual rate $r$, compounded once a year, to double. def years_to_double(r) { return 0.0 } show balance(1000.0, 0.05, 1.0, 10.0) show years_to_double(0.05) test "$1000 at 5% for 10 years, compounded once a year, is $1628.89" { assert_near(balance(1000.0, 0.05, 1.0, 10.0), 1628.89, 0.01) } test "compounded monthly it is $1647.01" { assert_near(balance(1000.0, 0.05, 12.0, 10.0), 1647.01, 0.01) } test "no time, no interest: the balance is the principal" { assert_near(balance(250.0, 0.08, 4.0, 0.0), 250.0, 1.0e-12) } test "at 5% a year the money doubles in 14.21 years, and the balance then is 2P" { t = years_to_double(0.05) assert_near(t, 14.2067, 1.0e-3) assert_near(balance(1.0, 0.05, 1.0, t), 2.0, 1.0e-9) } # SPDX-License-Identifier: MIT OR Apache-2.0 # SPDX-FileCopyrightText: 2026 The Viv authors