Hi, Is there a short way to create an array in which the elements are making a geometric series?
like for example the following array:
x=[1 2 4 8 16 32 64]
Thanks, Shir

 Akzeptierte Antwort

Roger Stafford
Roger Stafford am 19 Dez. 2016

2 Stimmen

A general form for a geometric series is:
[a,a*r,a*r^2,a*r^3,...]
You can generate n of these by:
s = a*r.^(0:n-1);

Weitere Antworten (1)

John D'Errico
John D'Errico am 19 Dez. 2016

2 Stimmen

2.^(0:6)

3 Kommentare

shir shalom
shir shalom am 19 Dez. 2016
Thank you, but actually if I want to start at 0.5 then it won't work.
Is there a way using multiplication instead of ^ ?
You could have said that the first time. But what is wrong then with this?
2.^(-1:6)
It really won't work? I guess I need to learn this new math then.
Or, for a more general form, with some other start point:
0.1*2.^(0:6)
Could I have used a loop? Of course. But why? Learn to use Matlab.
shir shalom
shir shalom am 20 Dez. 2016
Yes, sorry of course it works. I guess I was too tired to think last night. Thanks alot!

Melden Sie sich an, um zu kommentieren.

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by