In matlab Numbers in a series and While loop practice Write
In matlab
Numbers in a series and While loop practice
Write a function piprod to determine how many terms of the above series are required to approximate PI to within 0.00001 of Matlab\'s value for PI.
4n2 4m2 1 (2n)(2n) 2 2 4 4 6 6 8 8 (2n 1) (2n 1) 1 3 3 5 5 7 7 90Solution
% matlab code
function terms = piprod()
 approx = 1;
 terms = 1;
 while (abs(pi/2 -approx) > 0.00001)
 approx = approx*(4*terms*terms)/(4*terms*terms -1);
 terms = terms +1;
 end
 end
fprintf(\"Terms required: %d\ \",piprod());
 % output: Terms required: 39271

