# Answer to Question #52410 in MatLAB | Mathematica | MathCAD | Maple for Steph

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

__Answer:__a) 1^2 + 2^2 + 3^2 +· · ·+ 1000^2

-by loop:

**s=0;**

**for i=1:1000**

** s=s+(i*i);**

**end**

**s**

-by vector:

**r=linspace(1,1000);**

**s=sum(r.*r)**

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

by loop:

**s=0;**

**p=1;**

**for i=1:2:1003 **

** s=s+p/i;**

** p=p*(-1);**

**end**

**s**

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

**s=0;**

**k=1;**

**while (1/(k^2*(k+2)^2))>eps**

** s=s+1/(k^2*(k+2)^2);**

** k=k+2;**

**end**

**s**

`ï»¿`

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment