You can create a list of sequences and then use sapply
:
x= list(0:10, 0:20, 0:50, 0:100)
result <- sapply(x, function(k) sum(1/(k+1)^2))
result
#[1] 1.558 1.598 1.626 1.635
With a for
loop :
result <- numeric(length(x))
for(i in seq_along(x)) {
result[i] <- sum(1/(x[[i]]+1)^2)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…