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...

  • For this assignment, you will apply what you learned in analyzing for, while, and do-while loops...

    For this assignment, you will apply what you learned in analyzing for, while, and do-while loops by writing these statements yourself. The Java™ program you write should do the following: Display a pyramid of asterisks onscreen (i.e., a nested for loop) Display the integers 10 to 1 in decreasing order, one number per line (i.e., a while/do-whlie loop) Add 7 until the sum becomes greater than 157, at which point the program should display both the sum and the number...

  • 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,...

  • C++ CLASS FOR DEFINING COMPLEX NUMBERS (READ BELOW) Write a C++ defining a class for complex...

    C++ CLASS FOR DEFINING COMPLEX NUMBERS (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √ −1. You should represent a complex number here as two values of type double. You should name the variables real and imaginary. You can call the...

  • USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write...

    USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √−1. You should represent a complex number here as two values of type double. You should name the variables real...

  • 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.

  • 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....

  • 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__()...

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