MOO*_*OON 3 differential-equations julia
我想用Julia求解双摆方程。DifferentialEquations对于某些初始值,我收到错误:
WARNING: dt <= dtmin. Aborting. If you would like to force continuation with
dt=dtmin, set force_dtmin=true
Run Code Online (Sandbox Code Playgroud)
如果我使用force_dtmin=true,我会得到:
WARNING: Instability detected. Aborting
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么办。这是代码:
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))
Run Code Online (Sandbox Code Playgroud)
我最近更改了此警告,明确告诉用户这很可能是模型的问题。如果您看到此情况,则通常有两个可能的问题:
虽然 (1) 过去经常出现,但现在自动算法会自动检测它,因此问题几乎总是 (2)。
因此,您可以做的就是打印出计算出的导数,看看它是否符合您的预期。如果你这样做,那么你会注意到
thdot1 = du[1]
thdot2 = du[2]
Run Code Online (Sandbox Code Playgroud)
为您提供可以无限小/大的虚拟值。原因是因为你应该覆盖它们!所以看起来你真正想做的是计算前两个导数项并将它们用于第二组导数项。为此,您必须确保首先更新这些值!一种可能的代码如下所示:
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
Run Code Online (Sandbox Code Playgroud)
使:
| 归档时间: |
|
| 查看次数: |
1442 次 |
| 最近记录: |