【问题标题】:No method matching ^没有方法匹配^
【发布时间】:2019-03-10 19:06:37
【问题描述】:

我在 Julia 中创建了一个 UnitRange,并尝试创建一个 x 相对于 xx ^ 2 的图。我写了以下代码。

x = [-10:10]
p1 = plot(x, x)
p2 = plot(x, x.^2)

我收到以下错误:

MethodError: no method matching ^(::UnitRange{Int64}, ::Int64)
Closest candidates are:
  ^(!Matched::Float16, ::Integer) at math.jl:795
  ^(!Matched::Missing, ::Integer) at missing.jl:120
  ^(!Matched::Missing, ::Number) at missing.jl:93
  ...

Stacktrace:
 [1] _broadcast_getindex at ./none:0 [inlined]
 [2] getindex at ./broadcast.jl:515 [inlined]
 [3] copy at ./broadcast.jl:790 [inlined]
 [4] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(Base.literal_pow),Tuple{Base.RefValue{typeof(^)},Array{UnitRange{Int64},1},Base.RefValue{Val{2}}}}) at ./broadcast.jl:756
 [5] top-level scope at In[18]:3

我的代码有什么错误?

【问题讨论】:

  • 试试x = -10:10?
  • @daycaster 它有帮助。谢谢!!

标签: plot julia ijulia-notebook


【解决方案1】:

你可以改变:

x.^2

到:

x[1].^2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 2011-12-25
    相关资源
    最近更新 更多