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

Can someon help me with 9.16 please? by evaluating the my_sin (2) and comparing

ID: 3861294 • Letter: C

Question

Can someon help me with 9.16 please?

by evaluating the my_sin (2) and comparing it to the built-in MATLAB sine function. The value of pi can be approximated with the Gregory-Leibniz series summation pi/4 = 1 + 1/3 + 1/5 - 1/7 + 1/9- or pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 - The series converges very slowly. Calculate sr. using a midpoint break loop. Determine convergence by comparing successive values of the summation as you add additional terms until the difference between successive sums is less than 0.001. Set the maximum number of iterations to 3000. A store owner asks you to write a program for use in the checkout process The program should: Prompt the user to enter the cost of the first item.

Explanation / Answer

function estimated_pie = my_pie()
sum_new = 0
sum_old = 0
for i = 1:3000
sum_new = sum_old + 4*(((-1)^(i-1))/(2*i -1))
if (abs(sum_new - sum_old) <= 0.001)
break
end
sum_old = sum_new
end
estimated_pie = sum_new
end

estimated_pie = my_pie()
disp(estimated_pie)

// Sample run

estimated_pie =  3.1421   

3.1421