next up previous contents
Next: Exercise 6 (Vectors) Up: Vectors und Matrices (1) Previous: Vectors und Matrices (1)

Exercise 5 (Vectors)

Working with vectors: Calculate

\begin{displaymath}\sum_{k=1}^{k=n}k \hspace*{2cm}\sum_{k=1}^{k=n}k^2 \hspace*{2cm}\sum_{k=1}^{k=n}k^3 \end{displaymath}

for $n=10, n=100, n=10000$.

Solution:

>> n=10; k=1:n; 
>> sum(k), sum(k.*k), sum(k.^3)  % point!
ans = 55
ans = 385
ans = 3025
>> n=100; k=1:n;
>> sum(k), sum(k.*k), sum(k.^3)
ans = 5050
ans = 3.3835E5
ans = 2.5503E7
>> n=10000; k=1:n;
>> sum(k), sum(k.*k), sum(k.^3)
ans = 5.0005E7
ans = 3.3338E11
ans = 2.5005E15
0



Helmut Dersch
2009-03-15