Solution 1:[1]
We may use vectorized option in R
out <- sum((3^(1:100))/(factorial(2:101)))
out
[1] 5.361846
checking with a for loop
out2 <- 0
for(n in 1:100) out2 <- sum(out2, 3^n/factorial(n + 1))
out2
[1] 5.361846
Similarly, we can create the formula for the ones showed in the update
sum(((2^(5:15))/((5:15)^2)) + (((5:15)^4)/(4^(5:15))))
[1] 350.4776
sum(((1:11) * (5^(0:10)))/(14^(1:11)))
[1] 0.1728227
prod((2 * (2:22)) + (2/sqrt(2:22)))
[1] 7.117167e+27
Solution 2:[2]
vectorized option stated above is probably the most efficient way to do it.
If you want to see it in closer format to your formula for readability because you are new (as you pointed) you can do the following:
my_sum = 0
for(n in 1:100) {
my_sum = my_sum + 3^n / factorial(n+1)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | memo |

