# -*- coding: utf-8 -*-
"""
Created on Mon Aug 12 12:58:38 2024

@author: 102194
"""

import numpy as np
import matplotlib.pyplot as plt
import math as maths

pi = np.pi

# set up the range of x that we're interested in
x = np.linspace(-pi/2,3*pi/2,200)

#plt.plot(x,np.sin(x))
#plt.show()

# define the maximum term in the Taylor series
N = 15
x0 = pi/3

ftaylor = 0*x
for j in range(0,N+1):
    
    # work out the values of the derivative for the Taylor series
    if j%4==0:
        tcoeff = np.sqrt(3)/2
    elif j%4==1:
        tcoeff = 1/2
    elif j%4==2:
        tcoeff = -np.sqrt(3)/2
    elif j%4==3:
        tcoeff = -1/2
        
    print(j,tcoeff)  
    
    #add the next highest term to the Taylor series
    ftaylor = ftaylor + tcoeff/maths.factorial(j)*(x-x0)**j
    
    plt.plot(x,ftaylor)
    plt.show()
    
    input()
    
    

    