Say one invested $100 at 5% growth, annually, compounded. Assuming I’m not screwing up the formula, the value of the investment at the end of any given year can be expressed as f(t)=100(1.05)^t where t is the number of years that have elapsed since the initial investment.
Say after 20 years, the investment started to lose money at a rate of 5%, annually, compounded. The value of the investment at the end of any year can be expressed, again, assuming I’m not screwing up the formula, as f(t’)=f(20)(.95)^t’, where t’ is the number of years that have elapsed since the investment started to loss money. Say this happened for 20 years.
Is there a way of expressing the total growth and loss by a single function over the entire 40 years, rather than saying f(t) is in place for years 1 to 20 and f(t’) is in place for years 21 to 40?
Is the change from growth to shrinking abrupt, right at 20 years? If so, then there’s not going to be any nice, clean, well-behaved way to do it. But sometimes the world isn’t nice, clean, and well-behaved, and so there’s a function called the Heaviside function for dealing with such things. The Heaviside function itself is simple: H(x) = 0 for x < 0, and H(x) = 1 for x > 0 (what H(0) itself is, usually isn’t worried about; you can make it 0, 1/2, or 1, but since it’s only one point, it usually doesn’t matter).
To make a piecewise function like yours, then, you’d take f(t) = H(20-t)*f[sub]1/sub + H(t-20)*f[sub]2/sub. For the first timespan, the first Heaviside function is 1 and the second is zero, and so you’ve just got the first function, and for the second timespan, the first Heaviside function is 0 and the second is 1, so you’ve just got the second function.
EDIT: Snarky_Kong, that’s just the function for the shrinking part, which he already has. It won’t work for the growth part. The difficulty isn’t in either part; it’s in joining the two parts together.
You could also use the Iverson bracket, a somewhat more general form of the Heaviside step function or Kronecker delta. You put any boolean proposition in the function and it returns 1 if the proposition is true or 0 if it is false. So your function would be f(t) = [t<20]*f[sub]1/sub + [t>=20]*f[sub]2/sub.