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.
while pival-pi >err?
>>7811091
>matlab geniuses
>approximating via series
toppu kekku
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
God, yall are better help than my teacher.
>>7811091
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));
end
disp(Current);
>>7811550
Oh, and some part of the while loop where you increment Next by 4 each time it loops.
Can't be bothered checking it in matlab, but it should hopefully work.