import numpy as np import matplotlib.pyplot as plt import math # Question 1 def series(n, x): return (-1.)**(n)*x**(2*n+1)/math.factorial(2*n+1) # Question 2 x = np.arange(10) y = [series(i, 3) for i in x] y2 = np.cumsum(y) # Question 3 plt.plot(x, y, 'b-') plt.plot(x, y2, 'r-') plt.savefig('converge.png') plt.close() # Question 4 def value(x, n): val = 0 for i in range(n): val += series(i, x) return val # Question 5 t = np.linspace(0, np.pi*2, 30) st = np.sin(t) v = [value(x, 10) for x in t] # Question 6 plt.plot(t, st) plt.plot(t, v, '*') plt.savefig('sin.png') plt.close()