我想用朱莉娅的双摆方程来求解DifferentialEquations方程。对于一些初始值,我得到了错误:
WARNING: dt <= dtmin. Aborting. If you would like to force continuation with
dt=dtmin, set force_dtmin=true如果我使用force_dtmin=true,我得到:
WARNING: Instability detected. Aborting我不知道该做什么further.Here是代码:
using DifferentialEquations
using Plots
m = 1
l = 0.3
g = pi*pi
function dbpen(du,u,pram,t)
th1 = u[1]
th2 = u[2]
thdot1 = du[1]
thdot2 = du[2]
p1 = u[3]
p2 = u[4]
du[1] = (6/(m*l^2))*(2*p1-3*p2*cos(th1-th2))/(16-9*(cos(th1-th2))^2)
du[2] = (6/(m*l^2))*(8*p2-3*p1*cos(th1-th2))/(16-9*(cos(th1-th2))^2)
du[3] = (-0.5*m*l^2)*(thdot1*thdot2*sin(th1-th2)+(3*g/l)*sin(th1))
du[4] = (-0.5*m*l^2)*(-thdot1*thdot2*sin(th1-th2)+(g/l)*sin(th2))
end
u0 = [0.051;0.0;0.0;0.0]
tspan = (0.0,100.0)
prob = ODEProblem(dbpen,u0,tspan)
sol = solve(prob)
plot(sol,vars=(0,1))发布于 2018-08-24 14:58:51
最近,我将此警告改为显式地告诉用户,这很可能是模型的问题。如果您看到这一点,那么通常有两个可能的问题:
虽然(1)过去经常出现,但现在自动算法会自动检测它,因此问题几乎总是(2)。
所以你能做的就是打印出你计算出来的衍生品是什么,看看它是否与你所期望的相符。如果你这么做了,你会注意到
thdot1 = du[1]
thdot2 = du[2]是给你虚拟的值,它可以无限小/大。原因是因为你应该把它们改写!所以看起来你真正想做的是计算前两个导数项,并在第二组导数项中使用它们。要做到这一点,您必须确保首先更新值!一个可能的代码如下所示:
function dbpen(du,u,pram,t)
th1 = u[1]
th2 = u[2]
p1 = u[3]
p2 = u[4]
du[1] = (6/(m*l^2))*(2*p1-3*p2*cos(th1-th2))/(16-9*(cos(th1-th2))^2)
du[2] = (6/(m*l^2))*(8*p2-3*p1*cos(th1-th2))/(16-9*(cos(th1-th2))^2)
thdot1 = du[1]
thdot2 = du[2]
du[3] = (-0.5*m*l^2)*(thdot1*thdot2*sin(th1-th2)+(3*g/l)*sin(th1))
du[4] = (-0.5*m*l^2)*(-thdot1*thdot2*sin(th1-th2)+(g/l)*sin(th2))
end使:

发布于 2018-08-23 13:15:06
似乎你的歌很僵硬,默认情况下需要一个极小的dt。您可以切换到一个僵硬的ODE求解器,或者给出这样的提示:
sol = solve(prob,alg_hints=[:stiff])参考:包文档中的ODE示例
https://stackoverflow.com/questions/51983171
复制相似问题