MethodError: no method matching -(::Int64, ::Array{Float64,1})

Hi, I am a newbie in Julia, using version 1.1.1.

MethodError: no method matching -(::Int64, ::Array{Float64,1})

What is wrong with the following code?

x1 = collect(0:0.1:2)
x2a = 1-0.5x1
x2b = ifelse(2-2
x1.>=0,2-2*x1,0)

Thanks!

1 is an integer and 0.5x1 is a Vector. To do elementwise minus, do 1 .- 0.5x1 (or better 1 .- 0.5 .* x1).

2 Likes

Thank you!