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 ) ) ]
code. What is the best (and propably efficient) way to do it?
Finite Geometric SeriesSn=a1(1−rn)1−r,r≠1 , where n is the number of terms, a1 is the first term and r is the common ratio . Example 3: Find the sum of the first 8 terms of the geometric series if a1=1 and r=2 .
The formulas for geometric series with 'n' terms and the first term 'a' are given as, Formula for nth term: nth term = a r. Sum of n terms = a (1 - rn) / (1 - r) Sum of infinite geometric series = a / (1 - r)
What is the Formula of Finding GP Sum for Finite Terms? The GP sum formula used to find the sum of n terms in GP is, Sn = a(rn - 1) / (r - 1), r ≠ 1 where: a = the first term of GP. r = the common ratio of GP.
When we sum a known number of terms in a geometric sequence, we get a finite geometric series. We generate a geometric sequence using the general form: Tn=a⋅rn−1.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With