Question

How do I go about solving this problem in R?

# This is a challenge. Essentially, you will use loops to calculate the # sum of the sequence: 4/1 - 4/3 + 4/5 - 4/7 + 4/9 -

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# initiate the result as 0
result <- 0
for(i in 0:1000){
# Create a flag to identify which term to add and which term to subtract
# if iteration number is even then subtract, else add
# subtraction or addition can be done by multiplying the term with -1 or 1 accordingly
flag <- ifelse(i %% 2, -1, 1)
  
# convert the number into odd since the denominator of each term is an odd sequence
odd <- (2*i) + 1
  
# calculate the individual term
temp <- 4 / odd*flag
  
# Take the cumulative sum
result <- result+temp
}

result

Add a comment
Know the answer?
Add Answer to:
How do I go about solving this problem in R? # This is a challenge. Essentially,...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need this code in java. Loops do just what they sound like they should -...

    I need this code in java. Loops do just what they sound like they should - they perform a statement again and again until a condition is fulfilled. For this lab you will be practicing using loops, specifically a for loop. The for loop takes the form of: for(/*variable initialization*/;/*stop condition*/; /*increment*/){ //statements to be done multiple times } Task Write an application that displays every perfect number from 2 through 1,000. A perfect number is one that equals the...

  • Can somebody help me with this assignment. I will highly appreciate. Also, please display the output...

    Can somebody help me with this assignment. I will highly appreciate. Also, please display the output as well. I need to use JAVA to to write the program. This is the sample output provided by my professor. HOME WORK: due 09.17.2019 (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class- the numerator and the denominator. Provide a constructor...

  • SOLVE USING MAPLE! What would the codes be for solving with maple? I do know how...

    SOLVE USING MAPLE! What would the codes be for solving with maple? I do know how to solve by hand, but a picture of the code inputted in maple is what I’m stuck on. THANK YOU! Note how this formula for u(r, t) satisfies the wave equation and the boundary condition at z = 0, The other conditions in the wave problem do not concern the points in the region II and thus should not be checked. In the exercises,...

  • I want to know how to do this assignment!!! Help me please~ The first part of...

    I want to know how to do this assignment!!! Help me please~ The first part of your program should do the following: • Ask the user type of test they took. o (ACT or SAT) • If they said ACT then ask them their score o If their ACT score was between 0 and 7 say "Needs Work" o If their ACT score was between 10 and 20 say "Acceptable" o If they ACT score was above 20 say "Above...

  • Hello, I need someone to help me solving this problem, please. ================ For the code sequence...

    Hello, I need someone to help me solving this problem, please. ================ For the code sequence below: add $1, $2, $3 sub $4, $1, $5 and $6, $1, $7 or $8, $1, $9 xor $4, $1, $5 1) Draw the pipelined dependences. 2) Show the forwarding paths needed to resolve the data hazards.

  • Iterators provide a systematic way to access all of the elements in a collection. To define...

    Iterators provide a systematic way to access all of the elements in a collection. To define an iterator, we need to add the __iter__() method to the class over which we want to iterate. Consider the following lines of code: odd_numbers = Odds(9) for num in odd_numbers: print(num) This code iterates over all the odd numbers less than or equal to 9 starting from the number 1. It assumes that the Odds class is iterable, i.e., it contains an __iter__()...

  • How would I go about solving parts 2,3, and 4 in this problem? How would I...

    How would I go about solving parts 2,3, and 4 in this problem? How would I draw the product? I. (24 pts.) Indicate the type of reaction that will predominate (i.e., SN1, SN2, El, or E4), draw the structure of the major product when: 1. isopropyl chloride reacts with hydroxide predominate rxn. structure: 3. 2-iodopentane reacts with ethoxide in DMSO predominate rxn. structure: 2. t-butyl tosylate reacts with CH3OH predominate rxn. structure: 4. ethyl bromide reacts with CH30- predominate rxn....

  • I am confused as to some properties of solving for DFT and DTFT. I am given...

    I am confused as to some properties of solving for DFT and DTFT. I am given a series of x[n] values and have to determine the X[k]. The formula for R[k] is sum[x(n)cos(2pi*k*n/N)], which make sense. However, when I plug the values (1, -1, 1, -1) into the equation, I get zeros across the board. Matlab tell me that at k=2, R[2] should be 4, but the only way that make sense is if the summation is an alternating series....

  • Description The purpose of this challenge is to various flow looping and control structures. This challenge...

    Description The purpose of this challenge is to various flow looping and control structures. This challenge displays a menu and asks the user to perform various tasks. Requirements Show a menu to the user with the following choices: a, b, c, q (Show the menu once and use a do-while statement to prompt the user for a menu command): a – Display all odd numbers between n1 and n2. Ask the user to enter two numbers, n1 and n2, using...

  • we are currently using C++ through reply.it thanks for your help. 9. If we define f(r)=...

    we are currently using C++ through reply.it thanks for your help. 9. If we define f(r)= r"-c, then solving f(x) = 0 is equivalent to finding e/n for n > 0. Given an approximate value of r, the Newton-Raphson method consists of calculating a approximation rnew, by using new f(x) Inew r In our case, this reduces to: (n-1)r c Inew= nrn-1 I 2 Write & program to find cn for positive n and c. The program should prompt for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT