# Understanding an argument-modifying function

**URL:** <https://discourse.julialang.org/t/understanding-an-argument-modifying-function/75760>\
**Category:** General Usage\
**Tags:** question, tuple\
**Created:** [February 3, 2022, 9:04pm UTC](https://discourse.julialang.org/t/understanding-an-argument-modifying-function/75760 "2022-02-03T21:04:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wub7quxa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wub7quxa/32/33473_2.png) [@wub7quxa](https://discourse.julialang.org/u/wub7quxa)\
**Post date:** [February 3, 2022, 9:04pm UTC](https://discourse.julialang.org/t/understanding-an-argument-modifying-function/75760/1 "2022-02-03T21:04:38Z")

</div>

I am using NLsolve to solve systems of nonlinear equations. Everything works fine, but I want to understand what this function does:

```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! appears to be a function which changes F but leaves x unchanged, and it assumes that both F and x are 2-tuples. Why, then, can I not say

```julia
a=(1.1,1.2)
b=(2.1,2.2)
f!(b,a)

```

? How would I pass a and b to f! such that b is modified in terms of a? If I do it, I get

```julia

MethodError: no method matching setindex!(::Tuple{Float64, Float64}, ::Float64, ::Int64)

Stacktrace:
 [1] f!(F::Tuple{Float64, Float64}, x::Tuple{Float64, Float64})
   @ Main ./In[94]:2
 [2] top-level scope
   @ In[103]:1
 [3] eval
   @ ./boot.jl:360 [inlined]
 [4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1116

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [February 3, 2022, 9:08pm UTC](https://discourse.julialang.org/t/understanding-an-argument-modifying-function/75760/2 "2022-02-03T21:08:19Z")

</div>

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
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

```

---

<div class="post-metadata">

**Author:** ![wub7quxa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wub7quxa/32/33473_2.png) [@wub7quxa](https://discourse.julialang.org/u/wub7quxa)\
**Post date:** [February 3, 2022, 9:10pm UTC](https://discourse.julialang.org/t/understanding-an-argument-modifying-function/75760/3 "2022-02-03T21:10:39Z")

</div>

Thank you! That’s exactly what I was looking for!
