几何级数中的数字 [英] Numbers in Geometric Progression
本文介绍了几何级数中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何生成 R 中几何级数的数字序列?例如我需要生成序列:1、2、4、8、16、32等等......直到说一个有限值?
How can i generate a sequence of numbers which are in Geometric Progression in R? for example i need to generate the sequence : 1, 2,4,8,16,32 and so on....till say a finite value?
推荐答案
这是我要做的:
geomSeries <- function(base, max) {
base^(0:floor(log(max, base)))
}
geomSeries(base=2, max=2000)
# [1] 1 2 4 8 16 32 64 128 256 512 1024
geomSeries(3, 100)
# [1] 1 3 9 27 81
这篇关于几何级数中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文