250 likes | 341 Views
259 Lecture 6 Spring 2013. Recurrence Relations in Excel. 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.
E N D
259 Lecture 6 Spring 2013 Recurrence Relations in Excel
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.
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.
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.
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%.
Notes • In order for a recurrence relation to make sense, some of the x(i)’s must be specified as initial conditions. • 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.
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.
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 …
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.
Remarks • Closed-form solutions can’t always be found this easily. • The Fibonacci sequence recurrence relation also has a closed form: • The closed-form solution for Compound Interest is an exponential function with base (1+i).
Exponential Growth • A function x(n) = an • 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.
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 losesi% of its value each month. • Find a recurrence relation to describe this investment.
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?
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!
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.
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.
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
Example 3 (cont.) • Again, there is a fixed point for this recurrence relation, namely X = 100.
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.
References • A Course in Mathematical Modeling by Douglas Mooney and Randall Swift.