<jupyter_start><jupyter_text>周期驱动有阻尼非线性单摆的混沌特性  以前的作业中，我们已经定义了在给定时间区间内求解一般微分方程的函数dSolve，      [dSolve in Chap1](https://github.com/loading99pct/computationalphysics_N2013301020062/tree/master/chap-1)      借助之前的求解方法函数，定义函数dSolveUntil, 此函数不断迭代，直到状态（t,X）满足某个条件stopQ,   返回解列表，此函数结构由nestUntilList给出      已经定义了dSolveUntil,它和dSolve一样可以调用四种求解方法，默认采用 RK-4 求解   [dSolveUntil in Chap2](https://github.com/loading99pct/computationalphysics_N2013301020062/tree/master/Chap_2.1)          本次作业中：   1, 对初值的敏感依赖性   2, 庞加莱截面          对初值的敏感依赖性  dSolve可以调用四种求解方法，默认采用 RK-4 求解    定义周期驱动有阻尼非线性单摆的运动微分方程（被映射为某个函数）<jupyter_code>def forcedDampedNonlinearPendulum(omgd, fd = 1.2, q = 0.5 , gOverL = 1.):
    def foo(t,X):
        [omega, theta] = X
        return array([- gOverL*math.sin(theta) - q*omega + fd*math.sin(omgd*t), omega])
    return foo<jupyter_output><empty_output><jupyter_text>考虑在初始条件有微小差别下的情况，这里角度有细微差别    [omega, theta] = [0., 0.20]   [omega, theta] = [0., 0.21]    分别用两个初值求解运动方程<jupyter_code>ans1 = dSolve(forcedDampedNonlinearPendulum(2./3.), array([0., 0.20]), tMax, stepSize, method = "RK4")
ans1Omega = reduceStateList(ans1, [0])
ans1Theta = reduceStateList(ans1, [1])

ans2 = dSolve(forcedDampedNonlinearPendulum(2./3.), array([0., 0.21]), tMax, stepSize, method = "RK4")
ans2Omega = reduceStateList(ans2, [0])
ans2Theta = reduceStateList(ans2, [1])<jupyter_output><empty_output><jupyter_text>分别画出角速度随时间变化,角度随时间变化，以及相空间轨迹<jupyter_code># Omega
ddp(ans2Omega,["ForwardEuler"], xLabel = "t/s", yLabel = "Omega/ 1/s")
ddp(ans1Omega,["RK4"], xLabel = "t/s", yLabel = "Omega/ 1/s")
done()

# Theta
ddp(ans2Theta,["ForwardEuler"], xLabel = "t/s", yLabel = "Theta/ 1")
ddp(ans1Theta,["RK4"], xLabel = "t/s", yLabel = "Theta/ 1")
done()

# phase diag
easyPlotXYHoldON(getXiList(ans2,2),getXiList(ans2,1), "ForwardEuler","Theta/ 1","Omega/ 1/s", "Phase Diagram")
easyPlotXYHoldON(getXiList(ans1,2),getXiList(ans1,1), "RK4","Theta/ 1","Omega/ 1/s", "Phase Diagram")
done()<jupyter_output><empty_output><jupyter_text>角度随时间变化（未取模）   ![](https://raw.githubusercontent.com/loading99pct/computationalphysics_N2013301020062/master/Chap_3.2/pictures/1-theta.png)    角度随时间变化（取模）    ![](https://raw.githubusercontent.com/loading99pct/computationalphysics_N2013301020062/master/Chap_3.2/pictures/1-modTheta.png)    角速度随时间变化     ![](https://raw.githubusercontent.com/loading99pct/computationalphysics_N2013301020062/master/Chap_3.2/pictures/1-omega.png)    相图    ![](https://raw.githubusercontent.com/loading99pct/computationalphysics_N2013301020062/master/Chap_3.2/pictures/1-phase.png)    可以看出，初始结果的微小差别会随着时间被放大，并占据主导     庞加莱截面  将庞加莱截面定义为对解的频闪提取<jupyter_code>def poincareSection(solution, omgd, phase = 0., tmin = 50):
	def mulOfTQ(t, omgd):
		n = (t - phase/omgd)/ (2*math.pi/omgd)
		return fEqQ(round(n), n)
	n = len(solution)
	sol = solution#[int(round(0.2*n)):-1]
	sectionPoints = filter(lambda state: mulOfTQ(getT(state), omgd) and getT(state) > tmin, sol)
	return sectionPoints<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15865063460253842, 'fraction_numerical': 0.06078824315297261, 'mean_word_length': 5.885057471264368, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '45860', 'license': 'MIT', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1518, 'n_words': 164, 'path': 'Chapter3/chapter3.2/README.ipynb', 'repo_name': 'zhangzhihan/computationalphysics_n2014301020035', 'size': '2994'}