Question #52410

Write MATLAB programs to find the following sums with for loops and by vectorization. Time both versions in each case.

1^2 + 2^2 + 3^2 +· · ·+ 1000^2 (sum is 333,833,500).

1 − 1/3 + 1/5 - 1/7 + 1/9 -· · ·- 1/1003 (sum is 0.7849—converges slowly to π/4).

Sum the left-hand side of the series:

(1/1^2.3^2) + (1/3^2.5^2) + (1/5^2.7^2) +· · ·=(pi^2 - 8)/16 (sum is 0. 1169 − with 500 terms).

1^2 + 2^2 + 3^2 +· · ·+ 1000^2 (sum is 333,833,500).

1 − 1/3 + 1/5 - 1/7 + 1/9 -· · ·- 1/1003 (sum is 0.7849—converges slowly to π/4).

Sum the left-hand side of the series:

(1/1^2.3^2) + (1/3^2.5^2) + (1/5^2.7^2) +· · ·=(pi^2 - 8)/16 (sum is 0. 1169 − with 500 terms).

Expert's answer

a) 1^2 + 2^2 + 3^2 +· · ·+ 1000^2

-by loop:

-by vector:

b) 1 − 1/3 + 1/5 - 1/7 + 1/9 -· · ·-1/1003

by loop:

c) (1/1^2.3^2) + (1/3^2.5^2) + (1/5^2.7^2) +· ··

``

Learn more about our help with Assignments: ProgrammingMatlab

## Comments

## Leave a comment