python判断非法输入_试图改变odeint的容忍度,但得到“非法输入检测”和“无限循环”...

在使用Python的scipy.integrate.odeint求解微分方程时,遇到“非法输入检测”和“明显的无限循环”错误。代码尝试调整解算器的相对公差以减小数值解的变化,但问题依然存在。通过增加full_output参数并检查返回信息,发现'nje'有时为0,'message'显示内部错误。寻求解决方案。
摘要由CSDN通过智能技术生成

我得到如下微分方程y’’+a y’−y+b y^3=c cos(kx),初始条件y(0)=y’(0)=0,参数值a=0.05,b=k=1,c=0.5。在

现在,我要做的是减少解算器的相对公差,直到数值解y(t)在x=x_max处的变化小于10^8

这是我的代码:from scipy.integrate import odeint

from scipy.optimize import brent

import numpy as np

def de( Y, t ): # de as an array

a = 0.05 # parameters

b = 1.0

c = 0.5

k = 1.0

return np.array([Y[1], Y[0] - a*Y[1] - b*(Y[0])**3 - c*np.cos(k*t)])

def Ydiff(h, *args): # calculates difference between the solution Y1

de = args[0] # (with default relative error) and Y2 (with new

t = args[1] # relative error)

y0 = args[2]

Y1 = args[3]

Y2 = odeint( de, y0, t, full_output=0, rtol=h)

return np.linalg.norm(Y1[-1,0] - Y2[-1,0]) # linalg.norm isn't

# n

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值