Eublepharis
Eublepharis

Reputation: 35

Julia PyPlot can't create quadratic function

I'm trying to learn to plot things with Julia using PyPlot, and I tried to plot a quadratic function. It does not like how I'm squaring x. I tried using x**2 and x*x, and the compiler did not accept those either. What should I be using to square x? Thanks

Code @ line 7:

x1 = linspace(0,4*pi, 500); y1 = x^2

Error:

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:\Users\User\.julia\v0.4\CodeTools\src\eval.jl:32
in anonymous at C:\Users\User\.julia\v0.4\Atom\src\eval.jl:84
in withpath at C:\Users\User\.julia\v0.4\Requires\src\require.jl:37
in withpath at C:\Users\User\.julia\v0.4\Atom\src\eval.jl:53
[inlined code] from C:\Users\User\.julia\v0.4\Atom\src\eval.jl:83
in anonymous at task.jl:58
while loading C:\Users\User\Desktop\Comp Sci\Class\plotTest, in expression     
starting on line 7

Upvotes: 3

Views: 132

Answers (2)

Landon
Landon

Reputation: 828

You are trying to square all of the elements of an array. This means you need to use the element-wise version x.^2.

Upvotes: 1

Jeff Bezanson
Jeff Bezanson

Reputation: 3207

To square every element of an array, use x.^2.

Upvotes: 6

Related Questions