Element-wise exponentiation

The error message tells you what to do:

julia> 2 .^ (-n)
ERROR: DomainError with -1:
Cannot raise an integer x to a negative power -1.
Make x or -1 a float by adding a zero decimal (e.g., 2.0^-1 or 2^-1.0 instead of 2^-1), or write 1/x^1, float(x)^-1, x^float(-1) or (x//1)^-1

Here’s the result:

julia> 2.0 .^ (-n)
100-element Array{Float64,1}:
 0.5
 0.25
 0.125
 0.0625
 0.03125
 0.015625
 0.0078125
 0.00390625
 0.001953125
 0.0009765625
 0.00048828125
 0.000244140625
 0.0001220703125
 ⋮
 1.6155871338926322e-27
 8.077935669463161e-28
 4.0389678347315804e-28
 2.0194839173657902e-28
 1.0097419586828951e-28
 5.048709793414476e-29
 2.524354896707238e-29
 1.262177448353619e-29
 6.310887241768095e-30
 3.1554436208840472e-30
 1.5777218104420236e-30
 7.888609052210118e-31
3 Likes