The Gregory series(http://mathworld.wolfram.com/GregorySeries.html) is one formu
ID: 3565093 • Letter: T
Question
The Gregory series(http://mathworld.wolfram.com/GregorySeries.html) is one formula for computing pi/4 (multiply by 4 to get pi). Define error as the magnitude of the difference between the sum containing N terms and the true value of pi. Write a script which prompts the user for an error value, uses a loop to determine how many terms in the sum are necessary to achieve that error value, and prints the pi approximation, actual error, and number of terms. Test the script using error values of: 10-2, 10-4, and (if possible) 10-6
Explanation / Answer
clear all
clc
abs_err=10^-4 ;%Place all your error terms here;
pi_calc=0;
err=1;
k=0;
while (err > abs_err)
k=k+1;
pi_calc=pi_calc+(-1)^(k+1)/(2*k-1);
err=abs(pi-pi_calc*4);
end
k
err
Result for err=0.0001
k =
10000
err =
9.999999975862650e-05
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.