2. Sequences & Series
Home Up Quick Reference M-files Laser Printing 1. Matlab Basics 2. Sequences & Series 3. Taylor Series 4. Fields & Flows 5. ODE Models 6. Symbolic ODE 7. Systems & 2nd order 8. Numerical ODE 9. Laplace Transform

[Objectives | Exercises | Example ]

OBJECTIVES

To become acquainted with the computer lab and MATLAB by learning some simple MATLAB commands, copying output into a Word document, and printing to the local printer.

EXERCISES

1) Use MATLAB to generate the first 100 terms in the sequence a(n) define recursively by 

a(n+1)=pa(n)(1-a(n)) with p=2.9 and a(1)=.5

Plot your results. (See last weeks lab and Example A below as to how to do this.) Paste your picture into your word file. Do this by clicking on 'Edit' on the menu bar and then choosing 'Copy.' Now return to the word document and click on 'Edit' and then choose 'Paste.' This will paste the picture into the document. 

2) Redo Problem 1. with p=3.1 and paste your plots into your word document. (Notice how a small change in p drastically changes the behavior of the sequence {a(n)}.) 

3) Following Example B)  below, graph (on the same graph) the first 2000 partial sums of the harmonic series (i)

and the series (ii)

.

One of these series is convergent and the other is divergent, which is which? Does this match what your graphs seem to indicate?

EXAMPLES

Example A) In practice, sequences often arise from recursive formulas like in the first exercise or the following example. Suppose that you would like to compute the first 100 terms in the sequence defined recursively by

an=0.75(1-an-1) with a1=1.

This can be accomplished with the following command:

>> a(1)=1; for n=2:100; a(n)=.75*(1-a(n-1)); end
Notice that you can actually 'Cut and Paste' the above line starting after the prompt ">>" directly into MATLAB. Plotting this sequence is as easy as:
>> plot(a,'r.')
>>title('Plot of a(n)=.75*(1-a(n-1)) with a(1)=1')
which produces the figure below.

 

Jump to Additional Comments on Example A)  to learn more about this example. 

 

Example B) Consider the alternating series:

The "inline" command

The simplest way to define a new function in MATLAB is to use the "inline" command. For instance, we can create a function, f, that calculates the nth term in the above series.

>> f=inline('(-1).^(n+1)./(n.*log(n+1))','n')
Note the use of '.^','.*', and './' in the above example. This allows us to evaluate f on a list of numbers instead of just one number at a time. Now we can create a sequence, 'a', of values of f, and a sequence, 's', of partial sums of 'a'.
>> a=f(1:25);
>> s=cumsum(a);
In the above example, the notation '1:25' refers to the list of integers 1,2,3,...,24,25. In which case, we have 

a=[f(1) f(2) f(3) ... f(24) f(25)]  and  s=[f(1),f(1)+f(2),f(1)+f(2)+f(3),...,f(1)+f(2)+f(3)+...+f(25)]. 

We can now use the following commands to plot our sequences:

>> figure
>> plot(a,'r')
>> hold on
>> plot(s,'b')
>> xlabel('n')
>> title('Plots of a(n) (red dots) and s(n) (blue x''s)')

 

Additional Comments on Example A)

It's clear from the graph in Example A) that the sequence converges to some number slightly larger then 0.4. To get a better estimate, we can actually take a look at the data by typing the following command:

>> a
MATLAB will respond by displaying all 100 values of our sequence. Try it! But since we are only interested in approximating the limit of the sequence, let's just look at the last ten values. This can be accomplished by using the following command:
>> a(91:100)
The following lines of output will be displayed:

		ans =

		  Columns 1 through 7 

		    0.4286    0.4286    0.4286    0.4286    0.4286    0.4286    0.4286

		  Columns 8 through 10 

		    0.4286    0.4286    0.4286
At this point we might be inclined to believe that our sequence has a limit of exactly 0.4286. But just out of curiosity, we can have MATLAB display up to 15 significant digits by typing the following command
>> format long
(You can return to the original format by using the command "format short".) Now if we asked MATLAB to display the last 10 values again, it would return

		ans =
	
		  Columns 1 through 4 
	
		   0.42857142857468   0.42857142856899   0.42857142857326   0.42857142857006
	
		  Columns 5 through 8 

		   0.42857142857246   0.42857142857066   0.42857142857201   0.42857142857099

		  Columns 9 through 10 

		   0.42857142857175   0.42857142857118
Either way, the limit of an appears to be about 0.4286. In fact, this turns out to be the exact value of the limit which is .75/(1+.75)=.4286.

[Objectives | Exercises | Examples  | Top]

 

Jump to Bruce Driver's Homepage.                       Jump to Current Courses Page.

Last modified on September 18, 2000 at 05:29 PM.