Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
charlotte davis
charlotte davis le 2 Oct 2014
Modifié(e) : Mischa Kim le 2 Oct 2014
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

Réponse acceptée

Mischa Kim
Mischa Kim le 2 Oct 2014
Modifié(e) : Mischa Kim le 2 Oct 2014
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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by