resolve_ivp微分方程求解器,不对所有返回值进行积分的方法? [英] solve_ivp differential equation solver, way to not integrate all return values?

查看:72
本文介绍了resolve_ivp微分方程求解器,不对所有返回值进行积分的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有一个给出差分返回值的模型.而且还有一个非微分(z)的值

Hey i have a model which gives diferential return values. But also a value which isnt a differential (z)

def model(t, f):
x = f[0]
y = f[1]
dx_dt = 2x*y
dy_dt = x**3
z = 2*x

return dx_dt, dy_dt, z

我的求解器可以求解这些方程,并在各自的时间值处给我x和y.

My solver can solve this equations and give me x and y at the respective time values.

t = np.linspace(0, 10, 100)
f0 = [2, 1, 0]
result = solve_ivp(model, [np.min(t), np.max(t)], f0, t_eval=t)

但是现在我还想要我的z解决方案,它不应该由求解器集成.是否有可能只整合我的求解器的前两个值?但是不是第三个吗?

But now i want also my solution for z which should NOT be integrated by the solver. Is there any possibility to just integrate the first 2 values of my solver? But not the third?

推荐答案

嘿,谢谢您的解决方案.我认为此解决方案也可能有效:

Hey thank you for your solution. i think this solution may also work:

def model(t,y):

global inner_func
def inner_func(t,y):
    
    #differential Eq System

    return dx_dt, dy_dt, z

dx_dt, dy_dt, z = inner_func(t,y)
return dx_dt, dy_dt

t = np.linspace(0, 10, 100)
f0 = [2, 1, 0]
result = solve_ivp(model, [np.min(t), np.max(t)], f0, t_eval=t)

z = np.array([inner_func(t[i], result[i,:]) for i in range(len(t))])[:,2]

这篇关于resolve_ivp微分方程求解器,不对所有返回值进行积分的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆