#!/usr/bin/python3

import numpy as np
import matplotlib.pyplot as plt
import math as math

#Q1a
def f(n,x): #n-order Taylor series for sin(x) expanded at pi/3
    im = 0
    for i in range(0,n+1):
        if i%4<2:
            sign = 1
        else:
            sign = -1
        if i%2==0:
            im = im + (sign/(math.factorial(i)*2))*(x-np.pi/3)**i
        else:
            im = im + ((np.sqrt(3)*sign)/(math.factorial(i)*2))*(x-np.pi/3)**i
    return im

x = np.linspace(-np.pi/2, 3*np.pi/2) # set domain as [-pi/2,3pi/2]
plt.plot(x,f(10,x)) #plot f(x) with 10 terms
plt.show()
