方程式:1 + 2/3 +(2/3 * 4/5)+(2/3 * 4/5 * 6/7)+ ... +(2/3 * 4/5 ... 38/39)
热衷于尝试在Rstudio中求解此方程式,如果有人可以帮助我或为我指出解决该方程式的方向,我将不胜感激。谢谢:)
语言:R(基本软件包);界面:RStudio
答案 0 :(得分:1)
您可以使用seq
函数来构建分数,然后使用prod
来获取每个序列的乘积。
##define first element as 1
res=1
##for loop to get fractions and calculate product
for(i in 1:19){
res=c(res,prod(seq(2,i*2,2)/seq(3,i*2+1,2)))
}
##sum all elements
sum(res)
[1] 6.976346