[Objectives |
Exercises | Example ]
OBJECTIVES 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) . One of these series is convergent and the other is divergent, which is which? Does this match what your graphs seem to indicate? 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
This can be accomplished with the following command: >> a(1)=1; for n=2:100; a(n)=.75*(1-a(n-1)); endNotice 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.')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);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
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: >> aMATLAB 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.4286At 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.42857142857118Either 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.
|