Suppose I have some number a
, and I want to get vector [ 1 , a , a^2 , ... , a^N ]
. I use [ 1 , cumprod( a * ones( 1 , N - 1 ) ) ]
cod
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
What about a.^[0:N]
?