Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There are many formulas for calculating the approximate value of pi to a certain

ID: 3834475 • Letter: T

Question

There are many formulas for calculating the approximate value of pi to a certain degree of accuracy. One of them is given by the following summation series: pi = 4 sigma^n_k = 1 (-1)^k + 1/2k - 1 (The series can also be written as pi = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - ... up to n terms) Write a Matlab function pivalue to find the sum of this series for n terms, where n is any positive integer. Write a script file that prompts the user to input a value for n. From this script, call the pivalue function to find the value of pi for n terms. Sample output: Enter the number of terms you want in the pi series: 10000 Value of pi for 10000 terms = 3.141493 >>

Explanation / Answer

N = input('Enter the number of terms you want in the pi series: ');
AppPi = 0;
for n = 0 : N
AppPi = AppPi + 4 * (-1)^n / (2 * n + 1);
end
fprintf('Value of pi for %d terms = %f ', N, AppPi);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote