- If the number of iterations (series terms) is know, use a for-loop
- ii is the loop index, l is the approximation to pi/4
approximating pi with taylor series expansion to the 10,000th term
1 次查看(过去 30 天)
显示 更早的评论
This was my code: I=0
while (I<10000)
I=((-1)^I)/(2*I+1)
end
x=4*I
so when I do that the answer shows as
x =
NaN + NaNi
0 个评论
采纳的回答
Mischa Kim
2014-10-2
编辑:Mischa Kim
2014-10-2
charlotte, you are almost there:
l = 1;
for ii = 1:10000
l = l + ((-1)^ii)/(2*ii + 1);
end
x = 4*l;
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!