You can find any member in a geometric sequence using this mathematical function:
term = start * ratio ** (n-1)
Where:
term = term in the sequence you want
start = first member in the sequence
relation = general relation (i.e. the plural defining the sequence)
n = member number in the sequence in which you want
Using this information, write a function in R that provides any subset of the geometric sequence for any origin and relationship:
#begin = beginning of subset #end = end of subset geomSeq <- function(start,ratio,begin,end){ begin=begin-1 end=end-1 start*ratio**(begin:end) } geomSeq(1, 2, 1, 10) # [1] 1 2 4 8 16 32 64 128 256 512 geomSeq(10,3,1,8) # [1] 10 30 90 270 810 2430 7290 21870 geomSeq(10,3,4,8) # [1] 270 810 2430 7290 21870
More about geometric sequences
milo
source share