Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common way to generate finite geometric series in MATLAB

Tags:

series

matlab

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?

like image 536
UncleAli Avatar asked Jun 10 '11 13:06

UncleAli


People also ask

How do you write a finite geometric series?

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 .

What is the formula for finite geometric series and infinite geometric series?

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 finite GP?

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.

What is the meaning of finite geometric series?

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.


2 Answers

What about a.^[0:N] ?

like image 166
ThibThib Avatar answered Oct 12 '22 23:10

ThibThib


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
like image 31
eat Avatar answered Oct 13 '22 00:10

eat