# 开发时间 2024/10/7 23:18
import math
import numpy as np
import matplotlib.pyplot as plt
C = math.sqrt((15 + math.sqrt(65)) / 8)
m = 1000
m_1 = 100
m_2 = 15
m_3 = 5
def f_1(x_1, x_2 ,m = m):
    tmp = (x_1 + (1/(m**2))*x_2 + C)
    return -(2/5)*tmp**4 + (8/5)*C*tmp**3 + (3/2 - (12/5)*(C**2))*tmp**2 + ((8/5)*C**3 - 3*C)*tmp + 1

def f_2(x_1, x_2,m=m):
    tmp = (x_2 + (1/(m**2))*x_1 + C)
    return -(2/5)*tmp**4 + (8/5)*C*tmp**3 + (3/2 - (12/5)*(C**2))*tmp**2 + ((8/5)*C**3 - 3*C)*tmp + 1
# we take the same initial points
x_1 = 1.486
x_2 = 0.108
x =[x_1]
y =[x_2]
count=0
while count<10:
    tmp1 = x_1
    tmp2 = x_2
    x_1 = f_1(tmp1,tmp2,m_1)
    x_2 = f_2(tmp1,tmp2,m_1)
    x.append(x_1)
    y.append(x_2)
    count+=1
plt.plot(x, y, marker='o', linestyle='-', color='blue',label='m=100')  # 'o'表示点, '-'表示连线



x_1 = 1.486
x_2 = 0.108
x =[x_1]
y =[x_2]
count=0
while count<10:
    tmp1 = x_1
    tmp2 = x_2
    x_1 = f_1(tmp1,tmp2,m_2)
    x_2 = f_2(tmp1,tmp2,m_2)
    x.append(x_1)
    y.append(x_2)
    count+=1
plt.plot(x, y, marker='o', linestyle='-', color='green',label='m=15')  # 'o'表示点, '-'表示连线

x_1 = 1.486
x_2 = 0.108
x =[x_1]
y =[x_2]
count = 0
while count<10:
    tmp1 = x_1
    tmp2 = x_2
    x_1 = f_1(tmp1,tmp2,m_3)
    x_2 = f_2(tmp1,tmp2,m_3)
    x.append(x_1)
    y.append(x_2)
    count+=1
plt.plot(x, y, marker='o', linestyle='-', color='yellow',label='m=5')
plt.legend()# 'o'表示点, '-'表示连线
plt.xlabel(r'$x_1$')
plt.ylabel(r'$x_2$')
plt.title('Different Iteration Trajectory when taking different m')
plt.grid(True)


plt.savefig('Different Iteration Trajectory.pdf',format='pdf')
# 显示图像
plt.show()
