Presentation is loading. Please wait.

Presentation is loading. Please wait.

259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

Similar presentations


Presentation on theme: "259 Lecture 6 Spring 2013 Recurrence Relations in Excel."— Presentation transcript:

1 259 Lecture 6 Spring 2013 Recurrence Relations in Excel

2 2 Recurrence Relations  Recall the idea of recurrence relation, which we saw briefly in Lecture 1. In Example 4, we found 1+2+…+n in Excel by letting x(0) = 1 and defining x(n) := x(n-1) + n for n ≥ 2.  A recurrence relation (or recursive relation) is a function x defined on the non-negative integers such that x(n) = f(x(n-1), x(n-2), …, x(2), x(1), x(0)), i.e. the value of x at n is a function of the values of x at some or all of the non-negative integers less than n.

3 3 Example 1: Some Recurrence Relations  (a) Factorial function  x(0) = 1 x(n) = n*x(n-1) for n ≥ 1  Thus x(0) = 1  x(1) = 1*x(0) = 1  x(2) = 2*x(1) = 2*1 = 2  x(3) = 3*x(2) = 3*2 = 6  etc.

4 4 Example 1: Some Recurrence Relations (cont.)  (b) Fibonacci Sequence  x(0) = 1 x(1) = 1 x(n) = x(n-1) + x(n-2) for n ≥ 2  Hence, x(2) = x(1) + x(0) = 1 + 1 = 2  x(3) = x(2) + x(1) = 2 + 1 = 3  x(4) = x(3) + x(2) = 3 + 2 = 5  x(5) = x(4) + x(3) = 5 + 3 = 8  etc.

5 5 Example 1: Some Recurrence Relations (cont.)  (c) Compound Interest  Invest principal P in an account earning interest rate i per period.  Then the amount x(n) invested at time period n can be defined recursively by  x(0) = P x(n) = (1+i)*x(n-1) for n ≥ 1  Given a principal P = $1000, find x(5) with compounding once per year and an annual interest rate 6%.

6 6 Example 1: Some Recurrence Relations (cont.)

7 7 Notes 1.In order for a recurrence relation to make sense, some of the x(i)’s must be specified as initial conditions. 2.The number of “time steps” a recurrence relation makes reference to is called its order.  In Example 1(a) and 1(c), the order is 1.  In Example 1(b), the order is 2.

8 8 Closed-Form Solutions  Suppose we want to know x(100) for a given recurrence relation.  To do so, we need to compute x(99), which in turn requires x(98), … and so on, until we’ve found x(0).  This means that a recurrence relation may be “hard” to work with for large values of non-negative integer n.

9 9 Closed-Form Solutions (cont.)  Sometimes it is possible to rewrite a recurrence relation in an equivalent form that doesn’t require calculation of n function values to get x(n).  Notice that for the Compound Interest recurrence relation in Example 1(c),  x(1) = (1+i)*x(0) x(2) = (1+i)*x(1) = (1+i)*(1+i)*x(0)= (1+i) 2 x(0) … x(n) = (1+i) n *x(0)  This last expression can be shown to hold via induction …

10 10 Closed-Form Solutions (cont.)  We call the expression x(n) = (1+i) n* x(0) a closed-form solution of the recurrence relation for Compound Interest.  Compare this to the formula we saw in Lecture 2!!  Thus to find x(5) in this example, we could have used the closed-form solution to get x(5) = (1+0.06) 5 *x(0) = (1.06) 5 *1000 = $1338.23.

11 11 Remarks 1.Closed-form solutions can’t always be found this easily. 2.The Fibonacci sequence recurrence relation also has a closed form: 3.The closed-form solution for Compound Interest is an exponential function with base (1+i).

12 12 Exponential Growth  A function x(n) = a n  grows exponentially if a > 1,  decays exponentially if 0 < a < 1,  is a damped oscillation if -1 < a < 0,  is an undamped oscillation if a < -1,  and is constant or oscillates between two points if a = 0, 1 or -1.

13 13 Example 2: A “bad” investment!  We invest P dollars in the Jurassic Pickle company’s stock, hoping to strike it rich!  At the advice of our Fredward Smith investment advisor, we also dollar-cost average by purchasing h dollars of stock at the end of each month.  Unfortunately, the Jurassic Pickle stock loses i% of its value each month.  Find a recurrence relation to describe this investment.

14 14 Example 2 (cont.)  For this investment,  Let x(0) = P x(n) = (1-i)*x(n-1) + h for n ≥ 1  If i = 5% and h = 5 dollars, what happens in the “long run” to an initial investment of P = 50, 75, 100, 125, 150 dollars?

15 15 Example 2 (cont.)

16 16 Example 2 (cont.)

17 17 Example 2 (cont.)  Notice that for each choice of principal P, the stock investment value appears to approach the same value of $100, as n gets larger and larger!

18 18 Fixed Points  If a recurrence relation’s values eventually “settle down” to a fixed value X as n gets larger and larger, then we say X is a fixed point of the recurrence relation.  A fixed point of a recurrence relation of order one, x(n) = f(x(n-1)), is a number X, such that f(X) = X.

19 19 Fixed Points (cont.)  The recurrence relation in Example 2, has X = 100 as a fixed point.  In general, fixed points of first order recurrence relations x(n) = f(x(n-1)) can be found by solving X = f(X) for X.  If a recurrence relation has a fixed point, it may need to be found numerically!  For the relation in Example 2, we find from X = (1-i)*X+ h, that X = h/i = 5/0.05 = 100.

20 20 Example 3: Another investment!  Repeat Example 2 with an investment that pays 5% interest compounded monthly, with an allowance of $5 removed at the end of each month.  This time, the recurrence relation is  x(0) = P x(n) = (1+i)*x(n-1) - h for n ≥ 1

21 21 Example 3 (cont.)

22 22 Example 3 (cont.)

23 23 Example 3 (cont.)  Again, there is a fixed point for this recurrence relation, namely X = 100.

24 24 Stability of Fixed Points  We call the fixed point X = 100 for Example 2 a stable fixed point.  We call the fixed point X = 100 for Example 3 an unstable fixed point.

25 25 References  A Course in Mathematical Modeling by Douglas Mooney and Randall Swift.


Download ppt "259 Lecture 6 Spring 2013 Recurrence Relations in Excel."

Similar presentations


Ads by Google