Understanding an argument-modifying function

Tuples are immutable, the input F must be a vector, instead. (x can be a tuple, because it is not being mutated - but most likely will be a vector as well in the actual code).

julia> function f!(F, x)
           F[1]=x[1]^2+3*x[2]^2-9
           F[2]=17*x[2]-14*x[1]^2+49
       end
f! (generic function with 1 method)

julia> F = [1.1,1.2] # a vector
2-element Vector{Float64}:
 1.1
 1.2

julia> f!(F,(1,2))
69


2 Likes