Write MATLAB code to create and print a vector GS that stores the first 10 terms of the geometric sequence that halves each time: {1/2, 1/4, 1/8, 1/16, ... 1/1024 }
9 ビュー (過去 30 日間)
古いコメントを表示
this is what i have done but it is wrong
Initial=input('Enter initial value: ')
for i =1:10
y(i)=(Initial)*(0.5)
end
0 件のコメント
回答 (3 件)
Walter Roberson
2015 年 12 月 2 日
The problem requires that you name the variable GS. Also the question does not ask you to prompt for an initial value.
For a geometric sequence so always be multiplying the previous value by the multiplier, not the initial value.
0 件のコメント
Thorsten
2015 年 12 月 2 日
Initial=input('Enter initial value: ')
y(1) = Initial*0.5;
for i = 2:10
y(i)= y(i-1)*0.5
end
or following Stephens suggestion, without a loop
y = Initial./pow2(1:10);
or
y = Initial./cumprod([repmat(2, 1, 10)])
or
y = Initial./2.^(1:10);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!