解决solve_ivp问题

时间:2020-10-10 13:32:59

标签: python scipy physics

我目前正在处理ODE问题,并且在使用resolve_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 {G M 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,)一起广播”

0 个答案:

没有答案