Write a piece of R code to compute the following series:
em = 1 + 0.8 (1*80%) + 0.64 (0.8*80%) + 0.512 (0.64*80%) + …
em = function(n, r = 0.8){
Body of code
}
if you have any problem let me know i will try to help you. Thank you.
em <- function(n, r = 0.8){
sum <- 1
temp <- r
for (i in 1:n){
sum <- sum +(temp*temp)
temp <- temp*r
}
print(sum)
}
em(2)
em(5)
// Sample output for n=2 and n=5.
Get Answers For Free
Most questions answered within 1 hours.