gpt4 book ai didi

julia - Julia 中使用微分方程的二阶 ODE

转载 作者:行者123 更新时间:2023-12-01 11:11:11 29 4
gpt4 key购买 nike

我正在尝试使用 Julia 中的微分方程求解谐波振荡器。即:

using DifferentialEquations
using Plots

m = 1.0
ω = 1.0

function mass_system!(ddu,du,u,p,t)
# a(t) = (1/m) w^2 x
ddu[1] = (1/m)*(ω^2)*u[1]
end

v0 = 0.0
u0 = 1.0
tspan = (0.0,10.0)

prob = SecondOrderODEProblem{isinplace}(mass_system!,v0,u0,tspan,callback=CallbackSet())
sol = solve(prob)

但是好像不理解ODE的构造函数。运行后,我得到:

ERROR: LoadError: TypeError: non-boolean (typeof(isinplace)) used in boolean context
Stacktrace:
[1] #_#219(::Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{}}}}}, ::Type{SecondOrderODEProblem{DiffEqBas
e.isinplace}}, ::Function, ::Float64, ::Float64, ::Tuple{Float64,Float64}, ::DiffEqBase.NullParameters) at /Users/brandonmanley/.julia/packages/DiffEqBase/avuk1/src/problems/ode_problems
.jl:144
[2] Type at ./none:0 [inlined] (repeats 2 times)
[3] top-level scope at /Users/brandonmanley/Desktop/nBody/nBodyNN/test.jl:25
[4] include at ./boot.jl:328 [inlined]
[5] include_relative(::Module, ::String) at ./loading.jl:1105
[6] include(::Module, ::String) at ./Base.jl:31
[7] exec_options(::Base.JLOptions) at ./client.jl:287
[8] _start() at ./client.jl:460

有什么想法吗?

最佳答案

我强烈建议查看 some of the tutorials .这里有一些错误,已解决 in this tutorial on classical physics models .具体来说,如果您选择不能变异的状态变量(即标量),则不应使用就地修改函数。如果是这种情况,只需使用生成输出的异地表单即可。看起来像:

using DifferentialEquations
using Plots

m = 1.0
ω = 1.0

function mass_system!(du,u,p,t)
# a(t) = (1/m) w^2 x
(1/m)*(ω^2)*u[1]
end

v0 = 0.0
u0 = 1.0
tspan = (0.0,10.0)

prob = SecondOrderODEProblem(mass_system!,v0,u0,tspan)
sol = solve(prob)

关于julia - Julia 中使用微分方程的二阶 ODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60180865/

29 4 0
文章推荐: java - 即使返回也显示缺少返回语句的错误
文章推荐: 正则表达式无法对两个匹配项使用相同的字符
文章推荐: java - 从 JSoup 中的 html 中删除
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com