解决solve_ivp问题

问题描述

我目前正在处理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,)一起广播”

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)