我正在尝试使用跳蛙算法为 3 体问题编写代码。我使用 Piet Hut 和 Jun Makino 的“Moving Stars Around”作为指南。
指南中的代码是用 C 编写的,但在尝试使用 Python 作为开始之前,我试图遵循确切的工作流程。
我已经定义了时间步长dt = 0.01和持续时间t_end = 10,而不是提示输入。在第 5.4 节中,结果应该是:
|gravity> g++ -o leapfrog2 leapfrog2.C
|gravity> leapfrog2 > leapfrog2_0.01_10.out
Please provide a value for the time step
0.01
and for the duration of the run
10
Initial total energy E_in = -0.866025
Final total energy E_out = -0.866025
absolute energy error: E_out - E_in = 2.72254e-10
relative energy error: (E_out - E_in) / E_in = -3.14372e-10
连同一个圆形图。但是,我的代码的结果有所不同:
Initial total energy E_in = -0.8660254037844386
Final total energy E_out = -0.39922101519288833
absolute energy error: E_out - E_in = 0.46680438859155027
relative energy error: (E_out - E_in)/E_in = -0.5390192788244604
当然,在我绘制我的结果之后,它们不会绕圈子。
我想知道我在翻译代码时是否犯了错误。任何帮助,将不胜感激!
相关分类