朱莉娅积分微分方程:方法错误:无方法匹配



我正在尝试在Julia中矢量微分方程。但是我卡在以下错误警告上:

MethodError: no method match hDerivative(::Array{Float64,1}, ::Nothing,>::Float64) 最接近的候选人是: hDerivative(::Any, ::Any) at In[8]:3 hDerivative(::Any) at In[13]:3

我基本上不确定函数"hDerivative"的语法。我尝试返回微分,但也将"timederiv"作为函数 hDerivative 的参数,类似于我在 Julia 中关于微分方程的 tuturial 中看到的,尽管这看起来有点奇怪(我习惯了 python)。

这是我使用的代码示例:

using DifferentialEquations
N=10
J=randn(Float64,N,N)
g=1
function hDerivative(h,timederiv)
    timederiv=zeros(Float64,N)
    for i=1:length(h)
        for j=1:length(h)
            timederiv[i]=timederiv[i]+J[i,j]*tanh(h[j])            
        end
    end  
end
hinit=zeros(Float64,N)
tspan=(0.0,1.0)
prob = ODEProblem(hDerivative,hinit,tspan)
solve(prob)

谁能帮我?

@LutzL的评论完全正确,此代码的问题在于它没有定义文档中提到的导数函数。相反,以下利用(du,u,p,t)窗体的代码有效:

using DifferentialEquations
N=10
J=randn(Float64,N,N)
g=1
function hDerivative(timederiv,h,p,t)
    for i=1:length(h)
        timederiv[i] = 0
        for j=1:length(h)
            timederiv[i]=timederiv[i]+J[i,j]*tanh(h[j])            
        end
    end  
end
hinit=zeros(Float64,N)
tspan=(0.0,1.0)
prob = ODEProblem(hDerivative,hinit,tspan)
solve(prob)

最新更新