question:
calculating pi:
pi/4= 1-(1/3)+(1/5)-(1/7)+(1/9)-... (a)
which comes from
arctanx= x-(x^3/3)+(x^5/5)-(x^7/7)+(x^9/9)-... (b)
write a function to cumpute pi using question a. you should find that this series converges slowly. Determine how many terms are required to calculate pi to a relative accuracy of 10^-5.
My function:
function pi= calculating_pipi1=0prompt='calculate pi';n=input(100);x=1for i=1:n if mod(i,2)==1 pi1=pi1+(1/x); else pi1=pi1-(1/x); end x=x+2pi1 = 4 * pi1;error = abs(pi - pi1);fprintf('Calculated value of pi : %f\n', pi1);fprintf('Actual value of pi : %f\n', pi);fprintf('Error : %f\n', error);end end
i keep getting error using input. I have no idea what I am doing wrong.
Best Answer