259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

25
259 Lecture 6 Spring 2013 Recurrence Relations in Excel

Transcript of 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

Page 1: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

259 Lecture 6 Spring 2013

Recurrence Relations in Excel

Page 2: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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.

Page 3: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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.

Page 4: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

4

Example 1: Some Recurrence Relations (cont.)

(b) Fibonacci Sequence x(0) = 1

x(1) = 1x(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.

Page 5: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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%.

Page 6: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

6

Example 1: Some Recurrence Relations (cont.)

Page 7: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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.

Page 8: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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.

Page 9: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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 …

Page 10: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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.

Page 11: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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).

Page 12: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

12

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.

Page 13: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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.

Page 14: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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?

Page 15: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

15

Example 2 (cont.)

Page 16: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

16

Example 2 (cont.)Jurassic Pickle Stock Investment

$-

$20.00

$40.00

$60.00

$80.00

$100.00

$120.00

$140.00

$160.00

0 10 20 30 40 50 60 70

Months

Sto

ck

Va

lue

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

Page 17: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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!

Page 18: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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.

Page 19: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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.

Page 20: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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

Page 21: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

21

Example 3 (cont.)

Page 22: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

22

Example 3 (cont.)Example 3 Investment

$(1,000.00)

$(500.00)

$-

$500.00

$1,000.00

$1,500.00

0 10 20 30 40 50 60 70

Months

Inv

es

tme

nt

Va

lue

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

Page 23: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

23

Example 3 (cont.)

Again, there is a fixed point for this recurrence relation, namely X = 100.

Page 24: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

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.

Page 25: 259 Lecture 6 Spring 2013 Recurrence Relations in Excel.

25

References

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