Download presentation
Presentation is loading. Please wait.
Published byThomas Ross Modified over 9 years ago
1
1 Copyright M.R.K. Krishna Rao 2006 7.2 Solving Recurrence Relations Steps for solving a linear homogeneous recurrence relation of degree 2 : Step #1. Get the characteristic equation of the given recurrence relation. Step #2. Solve the characteristic equation to get the two roots r 1, r 2. The general solution is a n = 1 r 1 n + 2 r 2 n Step #3. Substitute the initial conditions into the general solution to find the constants 1 and 2.
2
2 Copyright M.R.K. Krishna Rao 2006 Complication: Repeating Roots EG: Solve a n = 2a n-1 -a n-2, a 0 = 1, a 1 = 2 Find characteristic equation by plugging in a n = r n : r 2 - 2r +1 = 0 Since r 2 - 2r +1 = (r -1) 2 the root r = 1 repeats. If we tried to solve by using general solution a n = 1 r 1 n + 2 r 2 n = 1 1 n + 2 1 n = 1 + 2 which forces a n to be a constant function ( ). SOLUTION: Multiply second solution by n so general solution looks like: a n = 1 r 1 n + 2 nr 1 n
3
3 Copyright M.R.K. Krishna Rao 2006 Complication: Repeating Roots Solve a n = 2a n-1 -a n-2, a 0 = 1, a 1 = 2 General solution: a n = 1 1 n + 2 n1 n = 1 + 2 n Plug into initial conditions 1 = a 0 = 1 + 2.0·1 0 = 1 2 = a 1 = 1 ·1 1 + 2 ·1·1 1 = 1 + 2 Plugging first equation 1 = 1 into second: 2 = 1+ 2 implies 2 = 1. Final answer: a n = 1+n
4
4 Copyright M.R.K. Krishna Rao 2006 Complication: Repeating Roots In general, if the characteristic equation has only one root, the following theorem helps! Theorem 2: Let c 1 and c 2 be real numbers with c 2 0. Suppose that r 2 – c 1 r – c 2 = 0 has only one root r 0. A sequence {a n } is a solution of the recurrence relation a n = c 1 a n-1 + c 2 a n-2 if and only if a n = 1 r 0 n + 2 nr 0 n, for n = 0, 1, 2, …, where 1 and 2 are constants.
5
5 Copyright M.R.K. Krishna Rao 2006 k-LiHoReCoCos Consider a k-LiHoReCoCo: It’s C.E. is: Thm.3: If this has k distinct roots r i, then the solutions to the recurrence are of the form: for all n≥0, where the α i are constants. Example 6? from textbook.
6
6 Copyright M.R.K. Krishna Rao 2006 Degenerate k-LiHoReCoCos Theorem 4: Suppose there are t roots r 1,…,r t with multiplicities m 1,…,m t. Then: for all n≥0, where all the α are constants. for all n≥0, where all the α are constants. Example 8? from textbook. Blackboard Ex. 18?, 20?, 22?
7
7 Copyright M.R.K. Krishna Rao 2006 The Nonhomogeneous Case Linear nonhomogeneous recurrences with constant coefficients may (unlike LiHoReCoCos) contain terms F(n) that depend only on n. Consider the Tower of Hanoi recurrence a n = 2a n-1 +1. Could solve using telescoping. Instead let’s solve it methodically. Rewrite: a n - 2a n-1 = 1 Solve with the RHS set to 0, i.e. solve the homogeneous case. Add a particular solution to get general solution.
8
8 Copyright M.R.K. Krishna Rao 2006 The Nonhomogeneous Case Add a particular solution to get general solution. Add a particular solution to get general solution. I.e. use rule: a n - 2a n-1 = 1 Solve with the RHS set to 0, i.e. solve a n - 2a n-1 = 0 Characteristic equation: r - 2 = 0 so unique root is r = 2. General solution to homogeneous equation is a n = 1 2 n General Nonhomogeneous = General homogeneous Particular Nonhomogeneous +
9
9 Copyright M.R.K. Krishna Rao 2006 The Nonhomogeneous Case Add a particular solution to get general solution for a n - 2a n-1 = 1. Use rule: There are little tricks for guessing particular nonhomogeneous solutions. For example, when the RHS is constant, the guess should also be a constant. So guess a particular solution of the form b n =C. Plug into the original recursion: 1 = b n – 2b n-1 = C – 2C = -C. Therefore C = -1. General solution: a n = 1 2 n -1. General Nonhomogeneous = General homogeneous Particular Nonhomogeneous +
10
10 Copyright M.R.K. Krishna Rao 2006 The Nonhomogeneous Case Finally, use initial conditions to get closed solution. In the case of the Towers of Hanoi recursion, initial condition is: a 1 = 1 Using general solution a n = 1 2 n -1 we get: 1 = a 1 = 1 2 1 -1 = 2 1 –1. Therefore, 2 = 2 1, so 1 = 1. Final answer: a n = 2 n -1
11
11 Copyright M.R.K. Krishna Rao 2006 More Complicated Example: Find the general solution to recurrence from the bit strings example: a n = 2a n-2 + 2 n-3 - a n-3 Rewrite as a n - 2a n-2 + a n-3 = 2 n-3 and solve homogeneous part: Characteristic equation: r 3 - 2r +1 = 0. Guess root r = 1 as integer roots. r = 1 works, so divide out by (r -1) to get r 3 - 2r +1 = (r -1)(r 2 +r -1).
12
12 Copyright M.R.K. Krishna Rao 2006 More Complicated r 3 - 2r +1 = (r -1)(r 2 +r -1). Quadratic formula on r 2 +r -1: r = (-1 5)/2 So r 1 = 1, r 2 = (-1+ 5)/2, r 3 = (-1- 5)/2 General homogeneous solution: a n = 1 + 2 [(-1+ 5)/2] n + 3 [(-1- 5)/2] n
13
13 Copyright M.R.K. Krishna Rao 2006 More Complicated Nonhomogeneous particular solution to a n - 2a n-2 + a n-3 = 2 n-3 Guess the form b n = k 2 n. Plug guess in: k 2 n - 2k 2 n-2 + k 2 n-3 = 2 n-3 Simplifies to: k =1/5. So particular solution is b n = 2 n /5 Final (nearly) answer: a n = 1 + 2 [(-1+ 5)/2] n + 3 [(-1- 5)/2] n + 2 n /5 General Nonhomogeneous = General homogeneous Particular Nonhomogeneous +
14
14 Copyright M.R.K. Krishna Rao 2006 Particular solutions table 1. Linear combinations work. n k 2. If f(n) contains r n and r is a characteristic root of multiplicity k, then multiply by n k.
15
15 Copyright M.R.K. Krishna Rao 2006 An example from another textbook Blackboard Exercises: 32, 34
16
16 Copyright M.R.K. Krishna Rao 2006 7.4 Generating functions Definition: Let S = {a 0, a 1, a 2,...} be an (infinite) sequence of real numbers. Then the generating function G(x), of S is the series G(x) = a k x k Example: Let S ={1,1,1,…}. Then its generating function G(x) = 1+ x + x 2 + x 3 + … = x k = 1/(1-x) Example: Let S ={0,1,2,3,…}. Then its generating function G(x) = x + 2x 2 + 3x 3 + … = kx k Example: If S is a finite set {1,1,1,1,1}. Then its generating function G(x) = 1+x +x 2 + x 3 +x 4 = (1-x 5 )/(1-x)
17
17 Copyright M.R.K. Krishna Rao 2006 Generating functions Example: Let S ={1,2,4,8,…}. Then its generating function G(x) = 1+ 2x + 4x 2 +8x 3 … = 2 k x k = 1/(1-2x) Example: Let S ={1,0,3,0,3 2,0,3 3,…}. Then its gen. function G(x) = 1 + 3x 2 + 3 2 x 4 + 3 3 x 6 + … = 1/(1-3x 2 ) Definition: Let F(x) = a k x k and G(x) = b k x k. Then F(x) + G(x) = (a k +b k )x k and F(x) + G(x) = (a k +b k )x k and Example: Let F(x) =G(x) = x k = 1/(1-x). Then F(x)G(x) = 1/(1-x) 2 = ( 1 j 1 k-j )x k = (k+1)x k =1+ 2x + 3x 2 +….
18
18 Copyright M.R.K. Krishna Rao 2006 Generating functions Useful Generating Functions: (1+x) n = C(n,k)x k -- Extended binomial theorem.(1+x) n = C(n,k)x k -- Extended binomial theorem. (1+ax) n = C(n,k)a k x k(1+ax) n = C(n,k)a k x k (1+x r ) n = C(n,k)x rk(1+x r ) n = C(n,k)x rk 1/(1-x) = x k = 1+ x + x 2 + x 3 + …1/(1-x) = x k = 1+ x + x 2 + x 3 + … 1/(1-ax) = a k x k = 1+ ax + a 2 x 2 + a 3 x 3 + …1/(1-ax) = a k x k = 1+ ax + a 2 x 2 + a 3 x 3 + … 1/(1-x r ) = x rk = 1+ x r + x 2r + x 3r + …1/(1-x r ) = x rk = 1+ x r + x 2r + x 3r + … 1/(1-x) n = C(n+k-1,k) x k1/(1-x) n = C(n+k-1,k) x k 1/(1+x) n = C(n+k-1,k)(-1) k x k1/(1+x) n = C(n+k-1,k)(-1) k x k 1/(1-ax) n = C(n+k-1,k) a k x k1/(1-ax) n = C(n+k-1,k) a k x k 1/(1+ax) n = C(n+k-1,k)(-a) k x k1/(1+ax) n = C(n+k-1,k)(-a) k x k (1-x r+1 )/(1-x) = 1+ x + x 2 + x 3 + … + x r(1-x r+1 )/(1-x) = 1+ x + x 2 + x 3 + … + x r
19
19 Copyright M.R.K. Krishna Rao 2006 Generating functions - Counting Example: How many solutions in N are there to x 1 +x 2 = 10, 1≤ x 1 ≤ 6 and 3 ≤ x 2 ≤ 9? x 1 +x 2 = 10, 1≤ x 1 ≤ 6 and 3 ≤ x 2 ≤ 9? The solution is the coefficient (here, 6) of x 10 in the generating function (x + x 2 + x 3 + …x 6 )(x 3 + x 4 + x 5 + …x 9 ). Example: How many solutions in N are there to x 1 +x 2 +x 3 = 17, 2 ≤ x 1 ≤ 5, 3≤ x 2 ≤ 6 and 4 ≤ x 3 ≤ 7? x 1 +x 2 +x 3 = 17, 2 ≤ x 1 ≤ 5, 3≤ x 2 ≤ 6 and 4 ≤ x 3 ≤ 7? The solution is the coefficient (here, 3) of x 17 in the generating function (x 2 +x 3 +x 4 +x 5 )(x 3 +x 4 +x 5 +x 6 )(x 4 +x 5 +x 6 +x 7 ). Practice Example 11 on P.490!
20
20 Copyright M.R.K. Krishna Rao 2006 Generating functions - Counting Example: How many ways can we feed r riyals to a vending machine that accepts tokens of value SR 1, SR 2 and SR 5 if the order does not matter ? The solution is the coefficient of x r in the generating function (1 +x +x 2 +x 3 …)(1 +x 2 +x 4 +x 6 …)(1 +x 5 +x 10 …). Here, we are basically allowing all possibilities of number of different tokens !
21
21 Copyright M.R.K. Krishna Rao 2006 Generating functions - Counting Example: How many ways can we feed r riyals to a vending machine that accepts tokens of value SR 1, SR 2 and SR 5 if the order does matter ? The number of ways to feed exactly n tokens of total value r riyals is the coefficient of x r in the generating function (x +x 2 +x 5 ) n. Here, we are counting all possible arrangements of n tokens. Each coin has 3 possibilities SR 1, SR 2 and SR 5. The total number of ways to feed tokens of total value r riyals is the coefficient of x r in the generating function 1 + (x +x 2 +x 5 ) + (x +x 2 +x 5 ) 2 +... = 1/(1- x -x 2 -x 5 ).
22
22 Copyright M.R.K. Krishna Rao 2006 Gen. functions – Solving rec. rel. Example: Solve a n a n-1 a n-2 a n-3 a 0 a 1 a 2 Example: Solve a n = a n-1 +8a n-2 - 12a n-3, with initial conditions a 0 = 2, a 1 = 3, and a 2 = 19. x 2 x 3 Therefore, g(x)-xg(x)-8x 2 g(x)+12x 3 g(x) = 2+x. That’s, g(x) =()/(1-x-x 2 x 3 That’s, g(x) =(2+x)/(1-x-8x 2 +12x 3 ).
23
23 Copyright M.R.K. Krishna Rao 2006 Generating functions – Solving recurrence relations Example (cont.): Solve a n a n-1 a n-2 a n-3 a 0 a 1 a 2 Example (cont.): Solve a n = a n-1 +8a n-2 - 12a n-3, with initial conditions a 0 = 2, a 1 = 3, and a 2 = 19. g(x) as sum of partial fractions Let’s try to write g(x) as sum of partial fractions 2 Thus, 2 + x = A(1 - 2x) 2 + B(1 + 3x)(1 - 2x) + C(1 + 3x). That’s, A + B + C = 2, - 4A + B + 3C = 1, 4A - 6B =0 The solution is A = 3/5, B = 2/5, C = 1. Therefore, a n nnnn a n =(3/5)(-1) n 3 n + (2/5)2 n + (n + 1)2 n.
24
24 Copyright M.R.K. Krishna Rao 2006 Gen. functions – Solving rec. rel. Example: Solve a n a n-1 a n-2 n a 0 a 1 Example: Solve a n = -3a n-1 +10a n-2 +3.2 n, with initial conditions a 0 = 0 and a 1 = 6. (1+3x-x 2 Therefore, g(x)(1+3x-10x 2 ) = -3+ 3/(1-2x). That’s, g(x) =/(1-2x) 2 x That’s, g(x) =6x/(1-2x) 2 (1+5x).
25
25 Copyright M.R.K. Krishna Rao 2006 Generating functions – Solving recurrence relations Example (cont.): Solve a n a n-1 a n-2 n a 0 a 1 Example (cont.): Solve a n = -3a n-1 +10a n-2 +3.2 n, with initial conditions a 0 = 0 and a 1 = 6. g(x) as sum of partial fractions Let’s try to write g(x) as sum of partial fractions 2 Thus 6x = A(1 - 2x)(1 + 5x) + B(1 + 5x) + C(1 - 2x) 2. That’s, A + B + C = 0, 3A + 5B - 4C = 6, -10A + 4C = 0 The solution is A = -12/49, B = 6/7, C = -30/49. a n nn nn a n =(-12/49)2 n + (6/7)(n + 1)2 n -(30/49)(-1) n 5 n.
26
26 Copyright M.R.K. Krishna Rao 2006 Generating functions – Solving recurrence relations
27
27 Copyright M.R.K. Krishna Rao 2006 Generating functions – Solving recurrence relations
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.