Common way to generate finite geometric series in MATLAB

谁说我不能喝 提交于 2019-12-01 16:31:28

What about a.^[0:N] ?

ThibThib's answer is absolutely correct, but it doesn't generalize very easily if a happens to a vector. So as a starting point:

> a= 2
a =  2
> n= 3
n =  3
> a.^[0: n]
ans =
   1   2   4   8

Now you could also utilize the built-in function vander (although the order is different, but that's easily fixed if needed), to produce:

> vander(a, n+ 1)
ans =
   8   4   2   1

And with vector valued a:

> a= [2; 3; 4];
> vander(a, n+ 1)
ans =
   8    4    2    1
  27    9    3    1
  64   16    4    1
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!