Deriving any Exponential Formula from a Pattern
Date: 01/18/2003 at 01:50:18 From: Lon Subject: Deriving any exponential formula from a pattern Dr. Math, I write a lot of software, and often I identify growth/decay patterns that could easily be represented as exponetial formulas. But I always struggle with deriving them and end up turning to other people for help. I would like to know the standard process for deriving an exponential formula. For example, I wrote a simple function which fades an image. The transparency of the image is a percent, where 100 is opaque. The simple formula I wrote runs in a loop, where: t = Target transparency (or alpha) c = Current transparency s = Speed (or rate) of fade F = final value The formula is: F = c + ((t - c)/s) I think that in the second iteration it would look like: F = (c + ((t - c)/s)) + ((t - (c + ((t - c)/s)))/s) Please help!
Date: 01/18/2003 at 23:12:43 From: Doctor Peterson Subject: Re: Deriving any exponential formula from a pattern Hi, Lon. As I understand it, your "F" means the next transparency, not really the "final" value; you could write the iteration as c[n+1] = c[n] + (t - c[n])/s This can be simplified to c[n+1] = (1 - 1/s)c[n] + t/s If we set A = 1 - 1/s and B = t/s this becomes c[n+1] = Ac[n] + B Repeating this, starting from a given the first value c = f, we have c = f c = Af+B c = A(Af+B)+B = A^2f + (A+1)B c = A(A^2f + (A+1)B)+B = A^3f + (A^2+A+1)B c = A(A^3f + (A^2+A+1)B)+B = A^4f + (A^3+A^2+A+1)B Clearly (I won't bother to prove it) c[n] = A^nf + (1+A+A^2+...+A^(n-1))B The geometric series can be summed using a familar formula, giving us c[n] = A^nf + B(A^n-1)/(A-1) = A^n(f + B/(A-1)) - B/(A-1) Replacing A and B with their values, B/(A-1) = -t, and c[n] = (1 - 1/s)^n (f - t) + t This clearly does what you want: it approaches t asymptotically (never actually getting there) in an exponential manner, starting at f. Your "speed" s, of course, is not really a speed of approach, but the reciprocal of the ratio by which the deviation from the target is decreased at each step. Setting s = 1/r, c[n] = t + (1-r)^n (f - t) That should be the formula you want. And normally we would start with this, and form an iterative approach from it, rather than derive it from the iterative formula the way I have. If you have any further questions, feel free to write back. - Doctor Peterson, The Math Forum http://mathforum.org/dr.math/
Date: 01/18/2003 at 23:27:06 From: Lon Subject: Deriving any exponential formula from a pattern Dr. Peterson, Thank you so much for that awesome derivation! I see very clearly how you derived it, and I think it will solve my current dilemma. However, the general process is still not clear to me. For example, how did you know to sub out the (1 -1/s)and the (t/s) ?
Date: 01/19/2003 at 22:48:50 From: Doctor Peterson Subject: Re: Deriving any exponential formula from a pattern Hi, Lon. I defined temporary variables A and B merely to make the equation look simpler and allow me to (a) see more clearly what had to be done, and (b) avoid typing too many complicated expressions. The work could have been done without that substitution, but when you have done this sort of algebra enough you learn how to save work. Also, my derivation could have been done more simply if I had chosen to use more insight into the problem (including your own insight that it is exponential) from the beginning, rather than just mechanically working out what successive iterations would do. Here's an alternative: Your iterative formula was: F = c + (t - c)/s I write this iteratively as c[n+1] = c[n] + (t - c[n])/s Your purpose here is to reduce the distance from t to c by the same ratio at each step, which is what makes this exponential. We can rewrite the equation to emphasize this: t - c[n+1] = t - c[n] - (t - c[n])/s = (t - c[n])(1 - 1/s) So the difference t - c is multiplied by 1 - 1/s at each iteration. Therefore if we temporarily define a new variable d[n] = t - c[n] our iteration is d[n+1] = d[n] (1 - 1/s) and we can easily see that d[n] = d (1 - 1/s)^n because we are multiplying by the same factor repeatedly. Putting this back in terms of c, c[n] = t - d[n] = t - (t - c)(1 - 1/s)^n That is the desired formula, equivalent to what I gave you last time. - Doctor Peterson, The Math Forum http://mathforum.org/dr.math/
Search the Dr. Math Library:
Ask Dr. MathTM
© 1994-2013 The Math Forum