I am trying to implement this function in Julia and I am not getting it. I think it's because of broadcasting, it doesn't seem to work with arrays. When I write the relational operators with dot (like .> instead of >), the number of errors decreases, but it accuses "TypeError: non-boolean (BitVector) used in boolean context". How can I fix this?
function Rulkov(N, X, Y, α)
global σ, μ
for n=1:1:N
if (X[n, 1]<=0)
X[n, 2] = α[n] / (1 - X[n, 1]) + Y[n, 1]
elseif (X[n, 1]>0 && X[n, 1]<(α .+ Y[n, 1]))
X[n, 2] = α[n] + Y[n, 1]
else
X[n, 2] = -1
end
Y[n, 2] = Y[n, 1] - μ*(X[n, 1] .+ 1) .+ μ*σ
end
return sum(X[:, 2])/N
end
Assuming that X
and Y
are matrices, X[n, 1]
is a scalar and α .+ Y[n, 1]
is a Vector
, so there is no meaningful comparison between these objects. So, depending on what you want you can either use
all(X[n, 1] .< (α .+ Y[n, 1])))
or (probably more correct from the mathematical point of view)
X[n, 1] < minimum(α .+ Y[n, 1])
or non-allocating version of the previous calculation
X[n, 1] < minimum(x -> x + Y[n, 1], α)
or (as it was proposed in comments)
X[n, 1] < minimum(α) + Y[n, 1]