Cumulative sum of a number to create an array

1 回表示 (過去 30 日間)
Isabelle Bester
Isabelle Bester 2019 年 9 月 24 日
編集済み: John D'Errico 2019 年 9 月 24 日
Hello!
I have a number (1182.225) and I am trying to create an array from this number that goes as follows:
Array = [1182.225, 1182.225*2, 1182.225*3, ..... 1182.225*24]
So that the array contains the number multiplied by 1 through 24 and each product is placed into the array. How can I write this in order to not type each multiplication manually?
Thanks for any feedback!
  2 件のコメント
Adam Danz
Adam Danz 2019 年 9 月 24 日
Matt J's answer does what you're describing but note that it's not a cumulative sum (as mentioned in your question title).
John D'Errico
John D'Errico 2019 年 9 月 24 日
編集済み: John D'Errico 2019 年 9 月 24 日
Why does this feel somehow too silly to post as an answer to me?
1182.225*cumsum(ones(1,24))
Like using a Mack truck, to carry a pea to Boston. Well, not quite as bad.
Ok, perhaps this?
cumsum(1182.225)*(1:24)
Ok, I'm getting the hang of it now.
cumsum(1182.225)*diff((1:25).^2 - (1:25))/2
That seems to be closer to my target. :)
Hmm. Lets see, the roots of a one of the Chebyshef family of polynomials are equally spaced. I could construct the proper member, in symbolic form, then use solve to compute the roots. Or, I could construct a 24x24 matrix, with the property that one of the eigenvectors has the right shape. Easy enough. Then eig will do the work for me.
Nope. I like Matt's answer myself. Stick with that. :)

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

回答 (1 件)

Matt J
Matt J 2019 年 9 月 24 日
編集済み: Matt J 2019 年 9 月 24 日
Array=1182.225.*(1:24)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by