Geometric series that halves but prints first 10 elements i.e. 1/2,1/4....,1/1028

12 Ansichten (letzte 30 Tage)
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??

Antworten (2)

Walter Roberson
Walter Roberson am 10 Dez. 2015
"For a geometric sequence so always be multiplying the previous value by the multiplier, not the initial value."

Stephen23
Stephen23 am 10 Dez. 2015
Bearbeitet: Stephen23 am 10 Dez. 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)

Kategorien

Mehr zu Language Support finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by