Julia integrating differential equations: MethodError: no method matching

Julia integrating differential equations: MethodError: no method matching

我正在尝试在 Julia 中向量化微分方程。但是我遇到了以下错误警告:

MethodError: no method matching hDerivative(::Array{Float64,1}, ::Nothing, >::Float64) Closest candidates are: hDerivative(::Any, ::Any) at In[8]:3 hDerivative(::Any) at In[13]:3

我基本上不确定函数的语法"hDerivative"。我尝试返回微分,但也试图将 "timederiv" 作为函数 hDerivative 的参数,类似于我在 tuturials 中看到的关于 Julia 微分方程的内容,尽管这看起来有点奇怪(我习惯于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)