Error plotting array with exponential operation

I am new to Julia and I am trying to create a plot with the following:

    xi2 = range(0,sqrt(6),step=1e-3)
    plot(xi2, 1-xi2^2/6, label="n = 0")

When I try this though, I have the error:

MethodError: no method matching ^(::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, ::Int64)
Closest candidates are:
  ^(::Union{AbstractChar, AbstractString}, ::Integer) at C:\Users\Acer\AppData\Local\Programs\Julia-1.7.0\share\julia\base\strings\basic.jl:721
  ^(::Rational, ::Integer) at C:\Users\Acer\AppData\Local\Programs\Julia-1.7.0\share\julia\base\rational.jl:475
  ^(::Complex{<:AbstractFloat}, ::Integer) at C:\Users\Acer\AppData\Local\Programs\Julia-1.7.0\share\julia\base\complex.jl:839

What am I missing here?

You need to use broadcasting to apply the ^ operation on all entries of the vector. The same for the - operation, that is:

1 .- xi2 .^ (2/6)
1 Like