chapter3

# chapter3 - Chapter 3 Sequences 3.1 Summation Nested loops...

• Notes
• 17

This preview shows pages 1–4. Sign up to view the full content.

Chapter 3 Sequences § 3.1 Summation Nested loops, while -loops with compound termination criteria § 3.2 Recursions One-term recursion, searching for a first occurrence, two-term recursion. In Chapter 2 we played with the sequence of regular n -gon areas { a n } where A n = n 2 sin 2 π n . We numerically “discovered” that lim n →∞ A n = π , a fact that is consistent with our geometric intuition. In this chapter we build our “ n -th term expertise” by exploring sequences that are specified in various ways. At the top of our agenda are sequences of sums like S n = 1 + 1 4 + 1 9 + · · · + 1 n 2 . Many important functions can be approximated by very simple summations, e.g., exp( x ) 1 + x + x 2 2! + · · · + x n n ! . The quality of the approximation depends upon the value of x and the integer n . Sometimes a sequence is defined recursively . The n -term may be specified as a function of previous terms, e.g., f n = 1 if n = 1 or 2 f n - 1 + f n - 2 if n 3 Sequence problems of this variety give us the opportunity to practice some difficult formula-to- program transitions. 75

This preview has intentionally blurred sections. Sign up to view the full version.

76 Chapter 3. Sequences 3.1 Summation The summation of a sequence of “regularly scheduled” numbers is such a common enterprise that a special notation is used. This is the “sigma” notation and here is an example: n X k =0 x k k ! = 1 + x + x 2 2! + · · · + x n n ! . The value of many regular summations is known. For example, the sum of the first n positive integers is given by n X k =1 k = n ( n + 1) 2 . (3.1.1) It is interesting to write programs that check rules like this. The program Example4 1 confirms that the sum of the first n integers is given by the above rule for n = 1 to 20. % Example3 1: Check the rule for the summation of the first n integers nmax= 20; % The no. of n-values used in the rule checking s= 0; % The sum of the sequence so far % Print the column headings fprintf(’ \ n’); fprintf(’ \ n n \ t Sum \ t n(n+1)/2 \ n’); fprintf(’--------------------------- \ n’); % Compute summation of first n integers for n= 1:nmax s= s+n; rhs= n*(n+1)/2; fprintf(’%3d \ t %3d \ t %8d \ n’, n, s, rhs); end Output: n Sum n(n+1)/2 ---------------- 1 1 1 2 3 3 3 6 6 . . . 19 190 190 20 210 210 The program uses a for -loop to actually compute the summation. The result is then printed side-by-side with the value of the summation formula. The program is not a proof of Equation
3.1. Summation 77 (3.1.1); it merely checks its correctness for a small set of possible n . Problem 3.1. Modify Example3 1 so that it confirms the following for n = 1 .. 20: n X k =1 k 2 = n ( n + 1)(2 n + 1) 6 . Problem 3.2. It is possible to find real numbers a, b, c, d, and e so that n X k =1 k 3 = an 4 + bn 3 + cn 2 + dn + e for all n . Note that if n is large enough, then n X k =1 k 3 an 4 . By dividing both sides by n 4 and assuming that n is large, we see that a n X k =1 k 3 ! /n 4 Write a program that estimates a using this approximation for n = 1 , . . . , 50.

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.
• Spring '07
• FAN/CHEW
• matlab, Recursion, Tn, Fibonacci number, RK, built-in function, ak−1

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern