如何强制solve_ivp仅允许集成变量的积极解决方案?
随着时间的流逝,我正在对表面上的冰冻进行建模。这需要计算“冷冻/熔化速率”,这可能大于或小于零。 我要施加的约束是,如果表面上的冷冻冰的量为零,如果冻结速率为负,则冰的量不能低于零(物理上不可能)。
是我想做的最小例子。您可以看到我试图强制解决方案值为> = 0的if语句,但是这不起作用。您如何使用solve_ivp执行此操作?
注意:此代码不运行,它只是显示我要做什么的外壳
def df(t,x,*system_constants):
##setting up derivative array
dxdt = np.zeros_like(x)
# [position][diff eq number]
# Ice solid deposition rate (dMi/dt), solving for total deposited ice
dxdt[0][0] = x[0][0] * a
if x[0][0] < 0:
x[0][0] = 0
return dxdt
#create your initial conditions
t0 = 0
tf = 10
t = (0,tf)
#solve the system
sol = solve_ivp(df, t, x0, args = system_constants, method = 'LSODA', dense_output=True)
I am modelling the freezing of ice on a surface over time. This requires calculating the 'rate of freezing/melting', which can be greater or less than zero. The constraint I want to impose is that if the amount of frozen ice on the surface is zero, and if the rate of freezing is negative, the amount of ice cannot go below zero (physically impossible).
This is a minimal example of what I am trying to do. You can see the if statement where I try to force the solution value to be >= 0, however this does not work. How do you do this with solve_ivp?
Note: this code does not run, it is just a shell to show what I am looking to do
def df(t,x,*system_constants):
##setting up derivative array
dxdt = np.zeros_like(x)
# [position][diff eq number]
# Ice solid deposition rate (dMi/dt), solving for total deposited ice
dxdt[0][0] = x[0][0] * a
if x[0][0] < 0:
x[0][0] = 0
return dxdt
#create your initial conditions
t0 = 0
tf = 10
t = (0,tf)
#solve the system
sol = solve_ivp(df, t, x0, args = system_constants, method = 'LSODA', dense_output=True)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论