Any MatLab Geniuses out there. I am completely lost on how to solve this. I think I need to use a while loop. Any help would really be appreciated.
>approximating via series
Yeah, you do need to use a while loop.
In informal terms, you're doing this
while |(pi - piVal) / (pi) * 100| > err
add another term to the approximation
increment my location in the series
when that's done you return your last piVal and how many terms you needed
It should be something like this:
Difference = 1;
Previous = 0;
Next = 1;
Precision = DESIRED NUMBER OF DECIMAL PLACES OF PI;
while Difference > 0
Current = Previous + (4/Next) - (4/(Next+2));
Difference = floor(Current*(10^Precision)) - floor(Previous*(10^Precision));