Array that contains a geometric series
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
shir shalom
le 19 Déc 2016
Commenté : shir shalom
le 20 Déc 2016
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
0 commentaires
Réponse acceptée
Roger Stafford
le 19 Déc 2016
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);
Plus de réponses (1)
John D'Errico
le 19 Déc 2016
2.^(0:6)
3 commentaires
John D'Errico
le 19 Déc 2016
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.
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!