next up previous contents
Next: Exercise 10 (Plotting) Up: Plotting Previous: Exercise 8 (Plotting)

Exercise 9 (Plotting)

Calculate the first 100 elements of the sequences

\begin{displaymath}x_n = \frac{n-1}{n}; x_n=\frac{n+1}{n}; x_n=\frac{n+(-1)^n}{n} \end{displaymath}

Plot $x_n$ versus $n$ using the command plot(n, xn). Variate the plotoptions (colors, symbols).

Solution:

>> n=1:100;
>> x1=(n-1)./n; x2=(n+1)./n; x3=(n+(-1).^n)./n;
>> plot(n,x1)        % Standard: blue, lines
>> hold
Current plot held.
>> plot(n,x2,'r')    % Color:  r,g,b,c,m,y,w.  
>> plot(n,x3,'g')



Helmut Dersch
2009-03-15