Trying to get a linear equation y = m*x + c
. I've the following lines of code, trying to add a scalar to an array.
m = 1.1; c = 0.11;
x = rand(1,2)
1×2 Array{Float64,2}:
0.920045 0.660015
y = m*x + c
ERROR: MethodError: no method matching +(::Array{Float64,2}, ::Float64)
Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...) at operators.jl:502
+(::Bool, ::T<:AbstractFloat) where T<:AbstractFloat at bool.jl:112
+(::Float64, ::Float64) at float.jl:395
...
Stacktrace:
[1] top-level scope at none:0
Currently using Julia 1.0. Directly adding a scalar to an array didn't work. In previous versions this used to work I suppose.
Scalar multiplication works
m*x
1×2 Array{Float64,2}:
1.01205 0.726016
But I've to define another array and then perform addition as shown.
c = [0.11 0.11]
y = m*x + c
1×2 Array{Float64,2}:
1.12205 0.836016
Isn't this an overhead? What difference does it make when I can perform scalar multiplication m*x
on arrays but not addition?