Question

7. Use your class to calculate rational approximations for π using the series π=1-1+1-1+, . Your program should ask the user
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given series

\pi =\frac{4}{1}-\frac{4}{3}+\frac{4}{5}-\frac{4}{7}+......

above series can be written as

2i-1 where n is the number of terms included

Matlab Code:

clear variables
close all
clc
n=input('\n Number of terms to be included for approximation:');
pi=0;
for i=1:n
pi=pi+(((-1)^(i+1))*(4/(2*i-1)));
end
fprintf('\n Approximate value of pi when %d terms are included is : %f\n',n,pi);

Sample Output:

Add a comment
Know the answer?
Add Answer to:
7. Use your class to calculate rational approximations for π using the series π=1-1+1-1+, . Your program should ask the user how many terms to include in the approximation. For full credit, use t...
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
  • Use your class to calculate rational approximations for π using the series π = 4 /1...

    Use your class to calculate rational approximations for π using the series π = 4 /1 − 4/ 3 + 4/ 5 − 4 /7 + . . . . Your program should ask the user how many terms to include in the approximation. For full credit, use the class above as much as possible (to do all the calculations).

  • Write a program that approximates the sum of this geometric series using a user- specified number...

    Write a program that approximates the sum of this geometric series using a user- specified number of terms. For example, if you named your program approx, calling approx(3) should use the first 3 terms of the series to calculate the approximation: Approximate result = 1/2 + 1/4 + 1/8 = 0.875... Note: the values are all powers of 1⁄2: (1/2)1, (1/2)2, (1/2)3, ... Next, have your program calculate the difference (rounded to 3 decimal places) between the value “1” and...

  • Write a program which will Ask the user a series of questions using the Scanner object Based on t...

    Write a program which will Ask the user a series of questions using the Scanner object Based on the input, draw a grid of star figures on the DrawingPanel You program should ask your user: . What R, G & B values to create a color to draw the figure? How many stars across should the fgure be? How many stars tall should the figure be? Note that your program does not need to error check the users responses Your...

  • Write a program that allows the user to enter a series of exam scores. The number...

    Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop...

  • *Write a parallel program pie.c in C or C++ (pie.cc) for Linux that computes an approximation of the number π using a se...

    *Write a parallel program pie.c in C or C++ (pie.cc) for Linux that computes an approximation of the number π using a series with N+1 terms.* --The series sum is partitioned in T non-overlapping partial sums, each computed by T separate child processes created with the fork() library function.* --This program demonstrates data parallelism and interprocess communication using pipes. Each child process could perform a (potentially) long computation on a separate CPU (or core). Depending on the computer architecture, the...

  • Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values...

    Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values for sin-1(x) from your program to those given by the Excel spreadsheet function ASIN(x). The Maclaurin arcsine expansion is given by x 3x 6 40 (2n)! sin1(x)-2((2n+1) Note: This function by definition is only defined for-1 SxS1. When you write the code for calculating it, you will need to include code that assigns a value to it that reflects it is undefined for values...

  • Your program will ask the user to enter the amount of money they want to borrow,...

    Your program will ask the user to enter the amount of money they want to borrow, the interest rate, and the monthly payment amount. Your program will then determine how many months it will take to pay off that loan, what the final payment amount will be, and how much interest was paid over that time. If the monthly payment amount isn't high enough to pay off more than one month's interest, your program should notify the user what the...

  • "Please Solve Problem 2 Please" Program 1(Total Point 15): You will use scanner class and ask...

    "Please Solve Problem 2 Please" Program 1(Total Point 15): You will use scanner class and ask users to enter numbers from 0 to 10 numbers. You will then extract only non prime numbers and store it in the set. You will then print the entire set contents. Problem 2(Total Point 15): Write a Java program that performs following things. Generate 10 random numbers Store all the numbers into the set Use the iterator or any other class to extract all...

  • * This is for CS 101 Java class. I can only use "while" loops. I cannot...

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

  • Write a class called OneRoundOneRollYahtzee. The program should behave the same as the InputOrGenerateDiceRolls (which is...

    Write a class called OneRoundOneRollYahtzee. The program should behave the same as the InputOrGenerateDiceRolls (which is as follows: InputOrGenerateDiceRolls program should ask the user whether the user prefers 1) to roll his/her own dice, 2) use computer-generated dice rolls, or 3) quit the program. If the user prefers to roll his/her own dice, the program should prompt the user to enter 5 digits in the range from 1-6 separated by spaces in any order with duplicates allowed. However, if the...

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