Cumulative sum of a number to create an array

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 comentarios

Adam Danz
Adam Danz el 24 de Sept. de 2019
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 el 24 de Sept. de 2019
Editada: John D'Errico el 24 de Sept. de 2019
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. :)

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 24 de Sept. de 2019
Editada: Matt J el 24 de Sept. de 2019
Array=1182.225.*(1:24)

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Sept. de 2019

Editada:

el 24 de Sept. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by