[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
Matlab/Numerical Methods
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /sci/ - Science & Math

File: P4MatLab.png (55 KB, 837x717) Image search: [iqdb] [SauceNao] [Google]
55 KB, 837x717
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.
>>
File: 1442068382496.jpg (26 KB, 353x334) Image search: [iqdb] [SauceNao] [Google]
26 KB, 353x334
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.
>>
>>7811550
>>7811552
i think this loop could work

while Difference > 0
Current = Previous + (4/Next) - (4/(Next+2));
Difference = floor(Current*(10^Precision)) - floor(Previous*(10^Precision));
Next=Next+4;
Previous=Current;
end