Advertisement
paulogp

Numero de Neper

Aug 7th, 2011
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # paulogp
  3. def factorial(n):
  4.     '''Retorna o factorial de n'''
  5.     f = 1
  6.     while (n > 0):
  7.         f = f * n
  8.         n = n - 1
  9.  
  10.     return f
  11.  
  12. def neper(x, n):
  13.     '''
  14.    Retorna e^x
  15.    e^0 = 1
  16.    e^1 = 2.71828182846
  17.    e^2 = 7.38905609893
  18.    x - potencia (float)
  19.    n - Numero de iteracoes
  20.  
  21.    PS: e^1 = (1+(1/n))^n
  22.    '''
  23.     f = 0.0e10
  24.     for i in range(0, n):
  25.         f = f + ( x**i / factorial(i) )
  26.  
  27.     print f
  28.  
  29. # Exemplo
  30. neper(1.0, 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement