Julia 中具有多种函数的积分

Integrals in Julia with multiple functions

提问人:Student Debil 提问时间:10/21/2023 最后编辑:Student Debil 更新时间:10/21/2023 访问量:50

问:

我是 Julia 的新手,我有一个代码:

using Symbolics, QuadGK,  SymbolicNumericIntegration

@variables M, m_0, ξ, ϵ_σ, ϵ_r, R̃, ε, U_λ, α,  β,v, λ, _ξ_, λ_c,φ
####################################

R̃ = ε^2 - U_λ - α * (α + 2*ε*λ*ϵ_σ)/ξ^2
X(ξ, ε, λ, α) = quadgk(_ξ_-> (λ + (α*ε)/(1-2/_ξ_))/( ( (α^2)/(1-2/_ξ_) + _ξ_^2  ) * sqrt(ε^2 - (1-2/_ξ_)*(1+λ^2/_ξ_^2) - (α^2+2*ε*λ*α)/(_ξ_^2)) ), ξ, Inf, rtol = 1e-5)[1] 
S(ξ, ε, λ, α, ϵ_σ,φ)  = exp(-(ε+ϵ_σ*v*sqrt(ε^2-1)*sin( (-X(ξ,ε, λ, α))*(φ-ϵ_σ*ϵ_r)))*(β)/sqrt(1-v^2) )[1]

print(integrate(ε*exp(-(ε+ϵ_σ*v*sqrt(ε^2-1)*sin( (-X(ξ,ε, λ, α))*(φ-ϵ_σ*ϵ_r)))*(β)/sqrt(1-v^2) )),(λ,0,10))

最后一个函数()给了我一个错误:integrate

ERROR: LoadError: MethodError: no method matching kronrod(::Type{Num}, ::Int64)
Closest candidates are:
  kronrod(::Any, ::Integer, ::Real, ::Real; rtol, quad) at ~/.julia/packages/QuadGK/ZWSGN/src/weightedgauss.jl:90
  kronrod(::Type{T}, ::Integer) where T<:AbstractFloat at ~/.julia/packages/QuadGK/ZWSGN/src/gausskronrod.jl:318
  kronrod(::Integer, ::Real, ::Real) at ~/.julia/packages/QuadGK/ZWSGN/src/gausskronrod.jl:343
  ...
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/QuadGK/ZWSGN/src/gausskronrod.jl:566 [inlined]
  [2] _cachedrule
    @ ~/.julia/packages/QuadGK/ZWSGN/src/gausskronrod.jl:566 [inlined]
  [3] cachedrule
    @ ~/.julia/packages/QuadGK/ZWSGN/src/gausskronrod.jl:571 [inlined]
  [4] do_quadgk(f::var"#1#2"{Num, Num, Num}, s::Tuple{Num, Num}, n::Int64, atol::Nothing, rtol::Float64, maxevals::Int64, nrm::typeof(LinearAlgebra.norm), segbuf::Nothing)
    @ QuadGK ~/.julia/packages/QuadGK/ZWSGN/src/adapt.jl:7
  [5] (::QuadGK.var"#50#51"{Nothing, Float64, Int64, Int64, typeof(LinearAlgebra.norm), Nothing})(f::Function, s::Tuple{Num, Num}, #unused#::Function)
    @ QuadGK ~/.julia/packages/QuadGK/ZWSGN/src/adapt.jl:235
  [6] handle_infinities(workfunc::QuadGK.var"#50#51"{Nothing, Float64, Int64, Int64, typeof(LinearAlgebra.norm), Nothing}, f::var"#1#2"{Num, Num, Num}, s::Tuple{Num, Num})
    @ QuadGK ~/.julia/packages/QuadGK/ZWSGN/src/adapt.jl:134
  [7] quadgk(::Function, ::Num, ::Vararg{Num}; atol::Nothing, rtol::Float64, maxevals::Int64, order::Int64, norm::Function, segbuf::Nothing)
    @ QuadGK ~/.julia/packages/QuadGK/ZWSGN/src/adapt.jl:234
  [8] quadgk(::Function, ::Num, ::Vararg{Any}; kws::Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:rtol,), Tuple{Float64}}})
    @ QuadGK ~/.julia/packages/QuadGK/ZWSGN/src/adapt.jl:229
  [9] X(ξ::Num, ε::Num, λ::Num, α::Num)
    @ Main ~/czarne_dziury.jl:8
 [10] top-level scope
    @ ~/czarne_dziury.jl:18

我试图用 QuadGK 计算这个积分,但它也不起作用。Cubature 和 HCubature 也出现错误。我知道这个积分很复杂,但对朱莉娅来说真的太复杂了吗?我希望这个问题有解决办法,出现错误的原因是因为我缺乏编程技能

Julia 符号数学 数值积分

评论

0赞 Robert Dodier 10/23/2023
有趣的问题,要调试这样的问题,我的建议是从问题的更简单版本开始,并尝试让它工作。如果它仍然不起作用,请继续简化它,直到您拥有最简单的示例。一旦你让某些东西起作用,然后朝着另一个方向前进,让它变得更加复杂,直到你回到完整的问题。
1赞 August 10/23/2023
QuadGK 用于数值积分,它不会进行符号积分

答: 暂无答案