필터 지우기
필터 지우기

approximating pi with taylor series expansion to the 10,000th term

조회 수: 2 (최근 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

채택된 답변

Mischa Kim
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;
  • 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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by