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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 2
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.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern