Question

* This is for CS 101 Java class. I can only use "while" loops. I cannot use "for", "do-while" or any other repetition method.*

d. Create a new project Lab04d. In this part, you are going to compute arctan(x) in radians The following formula approximates the value of arctan(x) using Taylor series expansion: 2k +1 tan-1 (x) = > (-1) 2k 1 k=0 Depending on the number of terms included in the summation the approximation becomes more accurate Your program will input from the user the value of x, which should be in the range (-1,1) and also the precision of the summation. You are going to calculate how many terms of the series are needed to approximate the sum up to the given precision for the given x value Since it is an alternating series, the absolute error of the approximation of arctan(x) by the 2k+1 partial sum, Σ-o(-1) 2k +1 72 lx2n+3 2k + 11-2n+3 2k+1 2k+1 tan-1(x)-〉 (-1) 2k +1 k=0 k =n+ 1 that is the absolute value of the (n+1)st term in the series. If this is bounded by absolute error of the approximation is desired to be less than some precision > 0, then it is - precision 2n+3 sufficient to set n to be smallest integer n such that

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

import java.util.Scanner;

public class arctan {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

double x, error, precision, steps=0, sum = 0;

System.out.print("Enter x: ");

x=input.nextDouble();

System.out.print("Enter precision: ");

precision=input.nextDouble();

error=1;

while (error>precision)

{

sum=sum+Math.pow(-1, steps)*(Math.pow(x, 2*steps+1))/(2*steps+1);

System.out.print("\nCurrent sum: "+sum);

error=(Math.pow(Math.abs(x), 2*steps+2))/(2*steps+3);

steps+=1;

}

System.out.printf("\n\nComputed with %.1e precision in %.0f steps\n", precision,steps);

System.out.printf("arctan("+x+") = "+sum+" radians");

input.close();

}

}

Enter x:76 Enter precision: .0001 Current sum: 0.76 Current sum: 0.6136746666666667 Current sum 0.6643851741866666 Current su

Add a comment
Know the answer?
Add Answer to:
* This is for CS 101 Java class. I can only use "while" loops. I cannot...
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
  • 6. (2n) a. Use the AST to show this series converges. b. Approximate the sum by calculating s c. ...

    6. (2n) a. Use the AST to show this series converges. b. Approximate the sum by calculating s c. Find a maximum for the absolute value of the error (error]) in this approximation. d. How many terms n must be added (i.e. s,) so that Jerrort .001 6. (2n) a. Use the AST to show this series converges. b. Approximate the sum by calculating s c. Find a maximum for the absolute value of the error (error]) in this approximation....

  • Consider the following alternating series. (-1)*+ 1 3k k=1 (a) Show that the series satisfies the...

    Consider the following alternating series. (-1)*+ 1 3k k=1 (a) Show that the series satisfies the conditions of the Alternating Series Test. 1 3" Since lim o and an + 1 for all n, the series is convergent (b) How many terms must be added so the error in using the sum S, of the first n terms as an approximation to the sum n=10 X (c) Approximate the sum of the series so that the error is less than...

  • Only C and D are necessary. An approximation attributed to both James Gregory (1638-1675) and Goltfried Leibniz (1646-1...

    Only C and D are necessary. An approximation attributed to both James Gregory (1638-1675) and Goltfried Leibniz (1646-1716) relies 1. tan +.", for-1 <xs 1. on the Taylor series for the inverse tangent (Sectlon 9.3): 3 S 7 a. Substitute x 1 into the Taylor series and write out a series that converges lo a/4. b. Write the first ten terms of the sequence of partial sums for the series. What is the error in the approximation to x/4 using...

  • We saw in class a result that provides an upper bound for the error approximation of...

    We saw in class a result that provides an upper bound for the error approximation of an alternating series by a given partial sum. Applying this result to the alternating series (1)n S = n=3 n (Inn)6 and its partial sum 5 (1)2 S5= compute the corres pond ing upper bound for the error s-s Give your answer to five decimals accuracy Number MIM8 We saw in class a result that provides an upper bound for the error approximation of...

  • Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos...

    Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos_series that takes that takes as its inputs, x and N and has output given by the sum in the N-term Maclaurin Series approximation for Cos(x). Hint: try a “for loop” and set “format long” in your code. You may use the MATLAB built-in function factorial() B. Check your code by finding the 2-terms, 3-terms, 4-terms, 5-terms and 6-terms Maclaurin Series approximations every 30 degrees...

  • Matlab function to solve an inequality that has a summation problem on one side. I have...

    Matlab function to solve an inequality that has a summation problem on one side. I have to write a function that uses a while loop and determines the biggest exponent value(k) in the summation out = symsum(2^i,i,o,k) that exceeds the input n in the inequality out > n so i need it to test the values of k from 1 on until out is the closest over n it can be. this assignment you will write two functions. The first...

  • Question 11 0/5 points n+1 satisfies all requirements of the Alternating Series Test. (You don't It...

    Question 11 0/5 points n+1 satisfies all requirements of the Alternating Series Test. (You don't It 2n=1 have to check that - trust me on this one.) (2n+1) (a) Use a calculator to evaluate the partial sum S3 of this series. Give the answer rounded to four decimal places. (b) Estimate the error of using S3 as an approximation to the sum of the series, i.e. estimate the remainder R3. Recall that the remainder estimate of the Alternating Series Test...

  • 2. It is probably evident that the Gregory/Leibniz series converges very slowly. The reason is that with x = 1, the powers of x in the Taylor series do not decrease in size. Here is an idea for obtai...

    2. It is probably evident that the Gregory/Leibniz series converges very slowly. The reason is that with x = 1, the powers of x in the Taylor series do not decrease in size. Here is an idea for obtaining better approximations. I need help with d, please. Thanks in advance 1, 2. It is probably evident that the Gregory/Leibniz series converges very slowly. The reason is that with the powers ofx in the Taylor series do not decrease in size....

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

  • 7. (a) Use the well known Maclaurin series expansion for the cosine function: f (x )...

    7. (a) Use the well known Maclaurin series expansion for the cosine function: f (x ) = cos x = 1 x? 2! + 4! х 6! + (-1)" (2n)! . * 8! 0 and a substitution to obtain the Maclaurin series expansion for g(x) = cos (x²). Express your formula using sigma notation. (b) Use the Term-by-Term Integration Theorem to obtain an infinite series which converges to: cos(x) dx . y = cos(x²) (c) Use the remainder theorem associated...

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