Geometric series that halves but prints first 10 elements i.e. 1/2,1/4....,1/1028
4 views (last 30 days)
Show older comments
My solution is:
for i=1:10
GS(i)=1/(2)^2;
fprintf('GS is: ',GS(i))
end
however it only prints 1/4. How would i fix this??
0 Comments
Answers (2)
Walter Roberson
on 10 Dec 2015
"For a geometric sequence so always be multiplying the previous value by the multiplier, not the initial value."
0 Comments
Stephen23
on 10 Dec 2015
Edited: Stephen23
on 10 Dec 2015
Much neater than using a loop:
>> 1./pow2(1:10)
ans =
0.5000 0.2500 0.1250 0.0625 0.0313 0.0156 0.0078 0.0039 0.0020 0.0010
or perhaps
>> fprintf('GS is: %f\n',1./pow2(1:10))
GS is: 0.500000
GS is: 0.250000
GS is: 0.125000
GS is: 0.062500
GS is: 0.031250
GS is: 0.015625
GS is: 0.007813
GS is: 0.003906
GS is: 0.001953
GS is: 0.000977
or perhaps even
>> rat(1./pow2(1:10))
ans =
1 + 1/(-2)
0 + 1/(4)
0 + 1/(8)
0 + 1/(16)
0 + 1/(32)
0 + 1/(64)
0 + 1/(128)
0 + 1/(256)
0 + 1/(512)
0 + 1/(1024)
0 Comments
See Also
Categories
Find more on Language Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!