Created
April 29, 2015 02:34
-
-
Save vitor-mariano/1e3748da6c54d3dbc169 to your computer and use it in GitHub Desktop.
Funções trigonométricas e números irracionais utilizando séries infinitas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
import math | |
def sin(x): | |
result = 0 | |
for n in range(1, 11): | |
result += (-1)**(n+1) * x**(2*n-1) / math.factorial(2*n-1) | |
return result | |
# Método usual, utilizando o função da biblioteca do Python | |
# Resultado: 0.909297426826 | |
print math.sin(2) | |
# Método manual, utilizando a série adequada | |
# Resultado: 0.909297426826 | |
print sin(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perceba que a série da função seno chega muito rápido a um valor preciso, neste caso, fazendo apenas 10 somas.