Advertisement
Guest User

tp2

a guest
Oct 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import math
  2.  
  3. def power_of(x, n):
  4.     j=1
  5.     for i in range(0, n):
  6.         j=j*x
  7.  
  8.     return j
  9.  
  10. def taylor_termo (x,n):
  11.    
  12.     """ A função acima descrita calcula um termo da série de taylor"""
  13.     return (power_of(-1,n)/math.factorial(2*n)) *power_of(x,2*n)
  14.  
  15. def taylor_cos(x,n,N):
  16.    
  17.     """ Esta função calcula o numero de termos da série de taylor dado pelo
  18.    valor do indice n do vetor N"""
  19.     j=0
  20.     for i in range(0,N[n]):
  21.         j=j+taylor_termo(x,i)
  22.     return j
  23.  
  24. def taylor_erro_cos(x,N,NDec):
  25.    
  26.     """A função definida calcula o valor correspondente aproximado pela série de taylor"""
  27.     resultado= []
  28.     for i in range (0,len(N)):
  29.         r= taylor_cos(x,i,N)
  30.         k=round(r,NDec[i])
  31.         resultado.append(k)
  32.     return resultado
  33.    
  34. N=[3, 4, 6, 10, 20]
  35. NDec=[4, 6, 8, 10, 10]
  36. n=math.pi
  37. print(taylor_erro_cos(n,N,NDec))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement