Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def power_of(x, n):
- j=1
- for i in range(0, n):
- j=j*x
- return j
- def taylor_termo (x,n):
- """ A função acima descrita calcula um termo da série de taylor"""
- return (power_of(-1,n)/math.factorial(2*n)) *power_of(x,2*n)
- def taylor_cos(x,n,N):
- """ Esta função calcula o numero de termos da série de taylor dado pelo
- valor do indice n do vetor N"""
- j=0
- for i in range(0,N[n]):
- j=j+taylor_termo(x,i)
- return j
- def taylor_erro_cos(x,N,NDec):
- """A função definida calcula o valor correspondente aproximado pela série de taylor"""
- resultado= []
- for i in range (0,len(N)):
- r= taylor_cos(x,i,N)
- k=round(r,NDec[i])
- resultado.append(k)
- return resultado
- N=[3, 4, 6, 10, 20]
- NDec=[4, 6, 8, 10, 10]
- n=math.pi
- print(taylor_erro_cos(n,N,NDec))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement