【发布时间】:2019-03-10 19:06:37
【问题描述】:
我在 Julia 中创建了一个 UnitRange,并尝试创建一个 x 相对于 x 和 x ^ 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