Cumulative sum of a number to create an array

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by