繁体   English   中英

如何将map过山车微分方程转换为scipy?

[英]How to map a roller coaster differential equation to scipy?

我想在 Scipy 中复制这篇精彩的博客文章,其中展示了如何使用此 ODE 系统模拟过山车物理

p'=v; v'=(-g k(p)/sqrt(1 + k(p)^2)

p = position on the track (measured by path length along the track)
v = velocity
k(p) = slope at point p (in code denoted as slope(p))
g = gravity
(-b/m) v = dampening term (not in code)

我不在乎阻尼。 只是一般概念。

我试图在 scipy 中复制它,其中的示例轨道只是以恒定的斜率下降(斜率 = -1)

import numpy as np
from scipy import integrate

def slope(p):
    return -1

def f(p, U):
    return [
            U[1],
            (-9.81 * slope(p))/ np.sqrt(1 + slope(p)**2)
            ]

sol = integrate.solve_ivp(f, (0, 5), [0, 0])
print(sol)

据我了解,返回的 function f 将时间映射到位置 p 和速度:f(time) -> [position, velocity]。

结果:

t: [0.0000e+00, 1.0000e-04, 1.1000e-03, 1.1100e-02, 1.1110e-01, 1.1111e+00, 5.0000e+00]
y[0]: [0.00000000e+00, 3.46835876e-08, 4.19671410e-06, 4.27336483e-04, 4.28106806e-02, 4.28183876e+00, 8.67089690e+01]
y[1]: [0.00000000e+00, 6.93671752e-04, 7.63038928e-03, 7.69975645e-02, 7.70669317e-01, 7.70738684e+00, 3.46835876e+01]]

然而,这不是我所期望的。

使用势能/动能方程并重新排列为 v: v = sqrt(2*g*h)

我希望在 -1 坡度 5m 后(意味着下降 5 米),速度为:

v = sqrt(2 * 9.81 * 5) = 9.904 (m/s)

但颂歌说它是34 (m/s)

我究竟做错了什么?

PS 我知道 g 可能需要更改为 -g 但无论哪种方式,数字都不会相加。

由于 k(p) = -1,你的加速度是 g/sqrt(2) 而不是 g

此外,您正在调用 function 以通过 5 秒的时间间隔。 5 秒后达到 34 m/s,而不是 5 米 = 9.81 / sqrt(2) x 5,这是正确的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM