Answer:a) 1^2 + 2^2 + 3^2 +· · ·+ 1000^2
-by loop:
s=0;for i=1:1000 s=s+(i*i);ends-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);endsc) (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;ends
Comments
Leave a comment