@.
adds a dot to every function call in the expression. In the case of 1.1, that includes the function ones
, which isn’t what you want. We can write out what the @.
is producing by hand like this:
P .= 1e-2 .* ones.(I, J) .* 1 # doesn't work
This fails because it’s trying to assign the entire output of ones
(a I x J
matrix) to each element of P
. Or, other words, it’s trying to do:
for i in eachindex(P)
P[i] = 1e-2 * ones(I, J) * 1
end
which doesn’t work.
The $
syntax within @.
means “don’t add a dot to this particular function call”, so:
@. 1e-2 * $ones(I, J) * 1
is equivalent to:
1e-2 .* ones(I, J) .* 1
i.e. the same as Option 1.2.