Question

Write a piece of R code to compute the following series: em = 1 + 0.8...

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
}

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Prompt: Write a code in MARS MIPS that uses a stack to recursively compute the series...
Prompt: Write a code in MARS MIPS that uses a stack to recursively compute the series from 1 to 10.
Use R Studio (show the code and output) Please write an R function named “outlier_detect” to...
Use R Studio (show the code and output) Please write an R function named “outlier_detect” to return or print out the outliers from a given data vector. outlier_detect = function(x){ #x: a column of numeric vector Body of code }
APPLIED STATISTICS 2 USE R CODE ! SHOW R CODE! Write a function to calculate the...
APPLIED STATISTICS 2 USE R CODE ! SHOW R CODE! Write a function to calculate the sum of cubes from 1 to n, but skip the multiple of 5. Say, if n=10, the result is 1^3+2^3+3^3+4^3+6^3+7^3+8^3+9^3. The input is the value of n, the output is the summation. (you need if statement to check whether a number is a multiple of 5.In R, a%%b is the remainder for a divided by b. So, we have 10%%5=0) APPLIED STATISTICS 2 USE...
C++ please! Write a recursive function to compute the sum of the Taylor series. use double...
C++ please! Write a recursive function to compute the sum of the Taylor series. use double taylor(int a, int n)
(1) Write R code to install the package named "MASS" only if the package is not...
(1) Write R code to install the package named "MASS" only if the package is not already installed on the machine. Then attach that package to your current workspace to use it in your programming. Your code below (2) Write R code to find what datasets are available only for the MASS package by creating a file named "R data sets". Your code below (3) Write R code to bring up the documentation page for the "Boston" dataset. Your code...
Write the R statements and associated output to compute the following quantities. Draw a graph of...
Write the R statements and associated output to compute the following quantities. Draw a graph of the probability mass function or probability density function illustrating the quantity being computed. (a) The 90th percentile of a U(0, 20) random variable. (b) The 20th percentile of a N(0,1) random variable. (c) The interquartile range of a N(5, 9) random variable. (d) The interquartile range of a binomial(10, 0.4) random variable.
write a java code. Write a program using loops to compute the sum of the 30...
write a java code. Write a program using loops to compute the sum of the 30 terms of the series below. 91/(3 + 2 + 2) + 92/(4 - 4 + 5) + 93/(5 + 6 - 8) + 94/(6 - 8 + 11) + 95/(7 + 10 + 14) + 96/(8 - 12 - 17) + . . . . Output: Term Ratio Sum 1 13 13 2 18.4 31.4 etc etc
Write an R code that does the following: (a) Generate n samples x from a random...
Write an R code that does the following: (a) Generate n samples x from a random variable X that has a uniform density on [0,3]. Now generate samples of Y using the equation: y = α/(x + β). For starters, set α = 1, β = 1 The R code: x=runif(n=1000, min = 0, max = 3) x y=1/x+1 y Please answer the following: b) Use plot(x,y) to check if you got the right curve. c) How does the correlation...
Write a piece of assembly code in SimpleRisc to find out if a number is a...
Write a piece of assembly code in SimpleRisc to find out if a number is a Factorian number or Dudeney number. Save 1 in r1 if it is a Factorian number; otherwise, save 0. Save 1 in r2 if it is a Dudeney number; otherwise, save 0. You have to write a single program to test both these conditions.
Write a MATLAB function that implements the difference equation for the system assuming null initial conditions....
Write a MATLAB function that implements the difference equation for the system assuming null initial conditions. Include source code . y(n) = x(n) + 2x(n-1) + x(n-2) + 0.8 y(n-1) - 0.64 y(n-2) Use Matlab to calculate the response of the system to p(n) = 0 for all n expect when p(10) = 1. Using stem, plot the resulting output to n=100 What is the amplitude of the output squence? Was the signal amplified? How much?