julia - Julia积分微分方程:MethodError:没有方法匹配
问题描述
我正在尝试在 Julia 中向量化微分方程。但我遇到以下错误警告:
MethodError: no method matching hDerivative(::Array{Float64,1}, ::Nothing, >::Float64) 最接近的候选是:hDerivative(::Any, ::Any) at In[8]:3 hDerivative(::任何)在 In[13]:3
我基本上不确定函数“hDerivative”的语法。我尝试返回微分,但也尝试将“timederiv”作为函数 hDerivative 的参数,类似于我在 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)
推荐阅读
- excel - 需要一个宏来询问某人的用户名,以便它可以打开工作簿
- mysql - 过滤数据库中表的方法,然后在每个表中更新相同的列值
- python - 如何设置平滑过渡的 Windows 10 桌面背景?
- javascript - 通过 Ajax 附加图像时如何检查何时加载了 srcset 图像
- typescript - 如何在 Visual Studio 2017 的 typescript 菜单中选择 esNext
- python - 自定义数据透视函数导致高页面错误率和句柄
- sonarqube - 如何克服 SonarQube 在单元测试和集成测试之间缺失的区别?
- ios - 在应用程序记录文本中持久(不在内存中)的最有效方式/策略是什么?
- java - 通过 Google 身份验证将客户端 Web id 放入 Strings.xml 是否安全?
- java - 无法运行默认测试,但应用程序工作正常。Spring boot 无法创建 entityManagerFactory bean,无法加载上下文