想要计算p=2时Ex和Ey随i(也就是n)的迭代问题,但是哪里错了[em06]
import numpy as npimport matplotlib.pyplot as plt
import cmath
# 常量初始化
E10=0
E20=0
a=0.8
b=0.9
k=0.4
N=500
# E实部,Ey虚部
E1=np.zeros(N)
E2=np.zeros(N)
# Ex实部,Ey虚部
Ex=np.zeros(N)
Ey=np.zeros(N)
x=y1=y2=[] # 这是新加的
p=2
for i in range(N - 1):
#先计算弧度
hudu = k - p / (1 + Ex[i] * Ex[i] + Ey[i] * Ey[i])
# 实部计算
Ex[i + 1] = a + b * (Ex[i] * cmath.cos(hudu).real - Ey[i] * np.sin(hudu).real)
# 虚部计算
Ey[i + 1] = b * (Ex[i] * cmath.sin(hudu).real - Ey[i] * np.cos(hudu).real)
x.append(i+1)
y1.append(Ex[i+1].real)
y2.append(Ey[i+1].real)
plt.plot(x, y1, 'r', label='实部Ex曲线')
plt.plot(x, y2, 'b', label='虚部Ey曲线')
plt.show()