朱莉娅·皮普图无法创建二次函数



我正在尝试学习使用PyPlot与Julia一起绘制事物,并且我试图绘制二次函数。它不喜欢我对x平方的方式。我尝试使用x**2和x*x,编译器也不接受这些。x的平方应该用什么?由于

代码@第7行:
x1 = linspace(0,4*pi, 500); y1 = x^2
错误:

LoadError: MethodError: `*` has no method matching *(::LinSpace{Float64},      
::LinSpace{Float64})
Closest candidates are:
*(::Any, ::Any, !Matched::Any, !Matched::Any...)
*{T}(!Matched::Bidiagonal{T}, ::AbstractArray{T,1})
*(!Matched::Number, ::AbstractArray{T,N})
...
in power_by_squaring at intfuncs.jl:80
in ^ at intfuncs.jl:108
in include_string at loading.jl:282
in include_string at C:UsersUser.juliav0.4CodeToolssrceval.jl:32
in anonymous at C:UsersUser.juliav0.4Atomsrceval.jl:84
in withpath at C:UsersUser.juliav0.4Requiressrcrequire.jl:37
in withpath at C:UsersUser.juliav0.4Atomsrceval.jl:53
[inlined code] from C:UsersUser.juliav0.4Atomsrceval.jl:83
in anonymous at task.jl:58
while loading C:UsersUserDesktopComp SciClassplotTest, in expression     
starting on line 7

要对数组中的每个元素进行平方,请使用x.^2 .

您正在尝试将数组中的所有元素平方。这意味着您需要使用元素的版本x.^2

最新更新