after how many terms does an equation have the same five decimals as pi/4?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Nora Al Allaf
am 25 Sep. 2020
Bearbeitet: madhan ravi
am 25 Sep. 2020
Hi,
so it's given that s = 1 − 1/3 + 1/5 − 1/7 + 1/9 − 1/11 + · · · + (−1)^n / (2n + 1)
what I need to do is, with a while-loop, see after how many terms (n) the equation above gives the same 5 first decimals as pi/4, which is 0.78539...
p = 0;
i = 0;
while 1 == 1 % Infinite loop
p = p + ((-1)^i)/(2*i + 1);
i = i + 1;
if
break
end
end
I just don't really know what to write in the if statement, tried so much but nothing is really working, would appreciate some help -_-
0 Kommentare
Akzeptierte Antwort
madhan ravi
am 25 Sep. 2020
Bearbeitet: madhan ravi
am 25 Sep. 2020
if abs(p - pi/4) < 1e-5
Look through the tag floating-point to know why tolerance is used to compare decimals.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!