import math
import matplotlib.pyplot as plt

# BEOS 2425

# Question 1.
def f(n,x):
    if n==0:
        return x
    else:
        u=f(n-1,x/3)
        return u*(3-4*u*u)
        
# Question 2.

plt.figure(1)
        
lx=[k*4*math.pi/100 for k in range(101)]
#ly0=[f(0,x) for x in lx]
ly1=[f(1,x) for x in lx]
ly2=[f(2,x) for x in lx]
ly3=[f(3,x) for x in lx]
ly4=[f(4,x) for x in lx]
ly5=[f(5,x) for x in lx]
plt.axis([0.,13.,-3.,3.])
#plt.plot(lx,ly0)
plt.plot(lx,ly1,color='black')
plt.plot(lx,ly2,color='blue')
plt.plot(lx,ly3,color='green')
plt.plot(lx,ly4,color='orange')
plt.plot(lx,ly5,color='red')
plt.show()


# Question 3.
Phi=lambda x: x*(3-4*x*x)

plt.figure(2)
LX=[-1+k/50 for k in range(101)]
LY=[Phi(x) for x in LX]
plt.plot(LX,LY)
plt.show()

plt.figure(3)
LX2=[-2*math.pi+k*math.pi/50 for k in range(101)]
LY2=[Phi(math.sin(x)) for x in LX2]
plt.plot(LX2,LY2)
plt.show()