Julia DifferentialEquations.jl 表示“InexactError”

发布于 2025-01-15 06:01:51 字数 879 浏览 5 评论 0原文

这是我第一次尝试复杂的耦合颂方程:

using DifferentialEquations
using Plots

function chaos!(dx, x, p, t)
    dx[1] = 1im*((p[3] * x[1] - 2 * real(x[2])) * x[1] - 0.5) -  x[1] / 2 
    dx[2] = -1im*(0.5 * p[2] * abs(x[2])^2 + x[2]) - x[2] * p[1] / 2
end

x0 = [1, 1];
tspan = (0, 100);
p =[0.001, 1.4, -0.95]
prob = ODEProblem(chaos!, x0, tspan, p)

sol = solve(prob,Tsit5())

它是这样的:

ERROR: InexactError: Float64(-0.5 - 3.45im)
Stacktrace:
  [1] Real
    @ .\complex.jl:44 [inlined]
  [2] convert
    @ .\number.jl:7 [inlined]
  [3] setindex!
    @ .\array.jl:903 [inlined]
  [4] chaos!(dx::Vector{Float64}, x::Vector{Float64}, p::Vector{Float64}, t::Float64)
    @ Main .\Untitled-1:5
  [5] ODEFunction
    @ C:\Users\CTCY\.julia\packages\SciMLBase\BoNUy\src\scimlfunctions.jl:345 [inlined]
.....

我不太明白它想告诉我什么。 “不精确错误”到底意味着什么?

This is my first attempt on a complex coupled ode equation:

using DifferentialEquations
using Plots

function chaos!(dx, x, p, t)
    dx[1] = 1im*((p[3] * x[1] - 2 * real(x[2])) * x[1] - 0.5) -  x[1] / 2 
    dx[2] = -1im*(0.5 * p[2] * abs(x[2])^2 + x[2]) - x[2] * p[1] / 2
end

x0 = [1, 1];
tspan = (0, 100);
p =[0.001, 1.4, -0.95]
prob = ODEProblem(chaos!, x0, tspan, p)

sol = solve(prob,Tsit5())

And it goes:

ERROR: InexactError: Float64(-0.5 - 3.45im)
Stacktrace:
  [1] Real
    @ .\complex.jl:44 [inlined]
  [2] convert
    @ .\number.jl:7 [inlined]
  [3] setindex!
    @ .\array.jl:903 [inlined]
  [4] chaos!(dx::Vector{Float64}, x::Vector{Float64}, p::Vector{Float64}, t::Float64)
    @ Main .\Untitled-1:5
  [5] ODEFunction
    @ C:\Users\CTCY\.julia\packages\SciMLBase\BoNUy\src\scimlfunctions.jl:345 [inlined]
.....

I don't quite get what it is trying to tell me. What does "inexacterror" even means?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

思念绕指尖 2025-01-22 06:01:51

初始条件需要很复杂:

x0 = ComplexF64[1, 1];

The initial condition needs to be complex:

x0 = ComplexF64[1, 1];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文