我目前正在处理 ODE 问题,并且在使用 solve_ivp 函数时我的代码出现了一些问题。到目前为止,这是我的代码:
def solve_ODE(N, tmax):
tspan = (0, tmax)
t = np.arange(0, tmax, N)
init_conditions = np.array([rs[0], rs[1], vs[0], vs[1]])
solution = integrate.solve_ivp(motion_function, tspan, init_conditions, t_eval=t)
return solution
我正在解决的功能是耦合 ODE:
$\frac{d^{2} x}{dt^2} = - \frac{GM x}{(x^2 + y^2)^{3/2}}$
$\frac{d^{2} y}{dt^2} = - \frac{GM y}{(x^2 + y^2)^{3/2}}$
def motion_function(t, f):
x = f[0]
y = f[1]
d2x_dt = -gg*mass*x / np.power((x**2 + y**2), 1.5)
d2y_dt = -gg*mass*y / np.power((x**2 + y**2), 1.5)
print(d2x_dt)
print(d2y_dt)
return d2x_dt, d2y_dt
错误提示“ValueError:操作数无法与形状 (2,) (4,) 一起广播”