matlab ode45三体问题,“毕达哥拉斯3Body Proxblem”ODE解算器测试的下一步

博主在尝试使用scipy.odeint求解毕达哥拉斯三体问题时遇到困难,由于系统对近距离相遇的处理不理想,导致集成失败。作者建议使用能处理多次近距离相遇的更精确积分器,并分享了尝试的代码。尽管调整了tol和hmax参数,但结果仍然不正确。视频链接提供了成功的模拟示例,但博主未能复现。代码中定义了粒子间相互作用的导数函数,并初始化了粒子位置和速度。
摘要由CSDN通过智能技术生成

我在尝试使用scipy.odeint整合毕达哥拉斯三体问题时遇到了困难。经过一番检查和网络搜索,我在这个非常有趣的集成中发现了以下内容discussion/tutorial:"After a discussion of the unit scaling in the next section many different integration algorithms are described in following sections. The author recommends, after writing your own integration program according to one of these algorithms, to begin the integration exercises with the figure “eight”, since it is easy to integrate due to its stability and the fact, that close encounters do not occur at all. Afterwards, you may try to solve the Pythagorean problem. The Pythagorean problem is difficult to integrate. A very accurate integrator must be used which is able to cope with the numerous close encounters."

因此,我的主要问题是:是否有其他python-ODE库可以参照上面的建议?或者,有人能帮我理解如何诱使odeint在这里工作吗?scipy.odeint每当我使用它时,它总是“刚刚工作”,所以这次我很惊讶。在

这个video和这个video都有很好的模拟结果

注意:标题不是打字错误-标题中有一个bot阻止了单词“problem”。在

我将在下面发布我的第一次尝试实现。我欢迎评论如何写得更好。通过调整tol(有时还有t中的间距,这很奇怪,因为这是插值,而不是{}的实际时间步长)。有一次我能画出一个看起来很正确的图(你可以在internet上看到它们),但我不记得是怎么画的。在

9df1385df242edf4596a5ac8bd38751a.pngdef deriv(X, t):

Y[:6] = X[6:]

r34, r35, r45 = X[2:4]-X[0:2], X[4:6]-X[0:2], X[4:6]-X[2:4]

thing34 = ((r34**2).sum())**-1.5

thing35 = ((r35**2).sum())**-1.5

thing45 = ((r45**2).sum())**-1.5

Y[6:8] = r34*thing34*m4 + r35*thing35*m5

Y[8:10] = r45*thing45*m5 - r34*thing34*m3

Y[10:12] = -r35*thing35*m3 - r45*thing45*m4

return Y

import numpy as np

import matplotlib.pyplot as plt

from scipy.integrate import odeint as ODEint

# Pythagorean Three Body Problem

# This script WILL NOT solve it yet, just for illustration of the problem

m3, m4, m5 = 3.0, 4.0, 5.0

x0 = [1.0, 3.0] + [-2.0, -1.0] + [1.0, -1.0]

v0 = [0.0, 0.0] + [ 0.0, 0.0] + [0.0, 0.0]

X0 = np.array(x0 + v0)

t = np.linspace(0, 60, 50001)

Y = np.zeros_like(X0)

tol = 1E-9 # with default method higher precision causes failure

hmax = 1E-04

answer, info = ODEint(deriv, X0, t, rtol=tol, atol=tol,

hmax=hmax, full_output=True)

xy3, xy4, xy5 = answer.T[:6].reshape(3,2,-1)

paths = [xy3, xy4, xy5]

plt.figure()

plt.subplot(2, 1, 1)

for x, y in paths:

plt.plot(x, y)

for x, y in paths:

plt.plot(x[:1], y[:1], 'ok')

plt.xlim(-6, 6)

plt.ylim(-4, 4)

plt.title("This result is WRONG!", fontsize=16)

plt.subplot(4,1,3)

for x, y in paths:

plt.plot(t, x)

plt.ylim(-6, 4)

plt.subplot(4,1,4)

for x, y in paths:

plt.plot(t, y)

plt.ylim(-6, 4)

plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值