Guest User

Untitled

a guest
Jan 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. from math import *
  2. from numpy import *
  3. from matplotlib.pylab import *
  4.  
  5.  
  6. def g(x, n):
  7. s = 0
  8. for j in range(n+1):
  9. s += ((-1)**j *x**(2*j+1.0))/factorial(2*j + 1)
  10. return s
  11.  
  12. x = linspace(0, 4*pi, 20)
  13. n_list = (1, 2, 3, 6, 12)
  14.  
  15. for n in n_list:
  16. plot(x, g(x, n))
  17.  
  18.  
  19. plot (x,sin(x))
  20. ylabel ("f(x, n)")
  21. xlabel ("x")
  22. ylim(-5,5)
  23. legend (["((-1)**j *x**(2*j+1))/factorial(2*j + 1)", "sin(x)"])
  24. show()
Add Comment
Please, Sign In to add comment