gpt4 book ai didi

Julia LoadError : MethodError: no method matching

转载 作者:行者123 更新时间:2023-12-05 02:57:47 25 4
gpt4 key购买 nike

我在运行以下 Julia 代码片段时遇到错误

using GR, Interact
t = 0:0.01:1
@manipulate for phi=0:0.1:6.28
plot(cos.(2π*t+phi))
end

LoadError: MethodError: no method matching +(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Float64)
Closest candidates are:
+(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:529
+(!Matched::Bool, ::T<:AbstractFloat) where T<:AbstractFloat at bool.jl:104
+(!Matched::Float64, ::Float64) at float.jl:395
...
in expression starting at C:\Users\W.Aftab\Desktop\Julia_Codes\src\003.jl:3
(::getfield(Main, Symbol("##9#10")))(::Float64) at 003.jl:4
map(::Function, ::Widget{:slider,Float64}) at Observables.jl:174
top-level scope at manipulate.jl:25

知道哪里出了问题吗?

最佳答案

以下应该会更好:

using GR, Interact
t = 0:0.01:1
@manipulate for phi=0:0.1:6.28
plot(cos.(2π*t.+phi)) #note the dot in ".+"
end

这是因为在该表达式中,t 是一个范围,因此 2pi*t 也是一个范围,因为在 Julia 中,标量和集合之间的乘积的值被定义为通过标量执行集合中每个元素的乘积。

在循环中的每次迭代中,phi 是一个标量。并且 + 操作未在标量和集合之间定义。它必须明确广播,例如使用 .+ 符号。

关于 Julia LoadError : MethodError: no method matching,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59569255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com