Create a Doubling Series

I am trying to use Matlab to create a series in which each term is the double of the previous term (ie. 1*2=2, 2*2=4, 4*2=8 etc.), but I can't find an effective way to do this. Any tips?

1 件のコメント

Graham Bamford
Graham Bamford 2020 年 9 月 14 日
How would you do this starting with any given number? i.e. starting with 250 and getting 500, 1000, 2000, 4000, 8000, etc...

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2016 年 9 月 2 日

0 投票

Choose ‘limit’ to be whatever you want:
limit = 10;
Out = 2.^[1:limit];
fprintf(1, [repmat('%6d',1,limit) '\n' repmat('%6d',1,limit) '\n'], [[1:limit]; Out]')
1 2 3 4 5 6 7 8 9 10
2 4 8 16 32 64 128 256 512 1024

2 件のコメント

Graham Bamford
Graham Bamford 2020 年 9 月 14 日
How would you do this starting with any given number? i.e. starting with 250 and getting 500, 1000, 2000, 4000, 8000, etc...
Star Strider
Star Strider 2020 年 9 月 15 日
Graham Bamford —
Try this:
Out = 250 * 2 .^ (0:6)
producing:
Out =
250 500 1000 2000 4000 8000 16000
.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

質問済み:

2016 年 9 月 2 日

コメント済み:

2020 年 9 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by