HMC Mathematics Department Computing Modules – Calculus Sequence and Series Convergence in MATLAB In this problem we’ll use Matlab tools to explore sequence and series convergence. A sequence is an ordered set { ak } defined by some function f where f (k ) = ak . The elements { ak } are called the terms of the sequence. For example, ak = 2k − 1, k = 1, 2, 3... defines the sequence 1, 3, 5, 7... (a) We’ll start by examining the sequence defined by: ak = 4(−1)k+1 , k = 1, 2, 3... 2k − 1 Write out the first 5 terms of the sequence by hand. (b) Next we’ll compute the terms of the series using Matlab. Using the inputs below, have MATLAB print out the first five terms of the sequence in (a). >> k=1:5 >> sequenceterms=4*((−1).ˆ(k+1))./(2*k−1) 1 Note that we used element-wise operations for exponentiation and division. We don’t have to use it here for multiplication because when we multiply a vector or matrix times a constant, Matlab assumes you are multiplying element-wise. 4(−1)k+1 Matlab evaluates the expression 2k−1 once for each k value from 1 to 5, producing a new array of the same size as the input array, k. What is a5 ? What is a10 ? To compute it, redefine k=1:10. (Note: Each time you redefine the vector k, you will need to redefine sequenceterms. Remember that the up-arrow key will retrieve previously entered functions.) What are a15 and a150 ? (c) This sequence does converge. Try more and more values until you can guess to which value the sequence converges. The sequence seems to converge to ____________. Of course, we haven’t proven anything about convergence, but the computation can give us an idea of what we might try to prove. (d) Determine the following limit by inspection (just looking at it and guessing). 4(−1)k+1 k→∞ 2k − 1 lim Is this result consistent with your answer for (c)? 2 (e) The corresponding series is the sum of the terms in the sequence. We can explore series convergence using the cumsum function. The output of cumsum is a vector for which the nth entry gives the sum of the first n terms of the input vector. For example, if you create the vector r=1:5, and perform cumsum(r), the output will be [1, 1+2, 1+2+3, 1+2+3+4, 1+2+3+4+5], which looks like [1,3,6,10,15]. Thus, we can define the vector of series terms as follows: >> seriesterms=cumsum(sequenceterms) Try using cumsum to explore the convergence or divergence of ∞ 4(−1)k+1 ∑ 2k − 1 k =1 Does the series seem to be converging or diverging? If it appears to converge, to what does it converge? 3 (f) We can also view partial sums using the plot function. The first input to plot specifies the vector plotted on the x-axis, and the second input specifies the vector plotted on the y-axis. For example, if x = -10:0.01:10, we get 2001 x values from 1 to 10. If we want to plot y = x2 , then we can input: >> plot(x, x.ˆ2) Use the following commands to plot k 4(−1) x+1 ∑ 2x − 1 x =1 over the interval 1 ≤ k ≤ 30. >> >> >> >> k=1:30 sequenceterms=4*((−1).ˆ(k+1))./(2*k−1); seriesterms=cumsum(sequenceterms); plot(k, seriesterms) Remember that the up-arrow key will retrieve previously entered functions. Note that we have used a semi-colon at the end of the line to suppress screen output. After creating your plot, add labels to the axes with the following commands: >> xlabel('k') >> ylabel('Partial Sum') How does this plot relate to your answers in (c) and (e)? 4 (g) Use Matlab to explore the behavior of each sequence. Explain whether the sequence seems to converge or diverge. Confirm your response analytically by examining the limit of the function as k ⇒ ∞. (i) cos(kπ ) 1 1 1 ,··· − , ,− ,··· , 2 3 4 k+1 (ii) 1 1 1 1 1, , , , · · · , 2 , · · · 4 9 16 k 5 (h) Use Matlab to explore the behavior of each series. Explain whether the series seems to converge or diverge. Confirm your response analytically. (i) ∞ cos(kπ ) k+1 k =1 ∑ (ii) ∞ 1 k2 k =1 ∑ Source: http://www.wm.edu/as/mathematics/documents/course_docs/math112/math112lab07.pdf 6
© Copyright 2025 Paperzz