Excel Definitions

259 Lecture 6 Spring 2017
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(1) = 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.
2
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*1 = 1
 x(2) = 2*x(1) = 2*1 = 2
 x(3) = 3*x(2) = 3*2 = 6
 etc.
3
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.
4
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%.
5
Example 1: Some Recurrence
Relations (cont.)
6
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.
3. In Example 1(a) and 1(c), the order is 1.
4. In Example 1(b), the order is 2.
5. For recurrence relation x(n) = 3*x(n-4),
the order is 4.
7
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.
8
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 …
9
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.
10
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).
11
Exponential Growth
 A function x(n) = an, defined for
integers n ≥ 0,
 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.
12
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.
13
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?
14
Example 2 (cont.)
15
Example 2 (cont.)
Jurassic Pickle Stock Investment
$160.00
$140.00
$120.00
Stock Value
$100.00
x(n) if P = $50
x(n) if P = $75
$80.00
x(n) if P = $100
x(n) if P = $125
x(n) if P = $150
$60.00
$40.00
$20.00
$0
10
20
30
40
50
60
70
Months
16
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!
17
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.
18
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.
19
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
20
Example 3 (cont.)
21
Example 3 (cont.)
Example 3 Investment
$1,500.00
Investment Value
$1,000.00
$500.00
x(n) if P = $50
x(n) if P = $75
x(n) if P = $100
x(n) if P = $125
x(n) if P = $150
$0
10
20
30
40
50
60
70
$(500.00)
$(1,000.00)
Months
22
Example 3 (cont.)
 Again, there is a fixed point for this
recurrence relation, namely X = 100.
23
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.
24
References
 A Course in Mathematical Modeling by
Douglas Mooney and Randall Swift.
25