Hi. I’m interested in ‘nlsolve’ function for solving system of equations.

Let us consider simple example:

Eq.1: y=a+x

Eq.2: y=2x-1,

where a is a vector that it can take values 3 and 5.

I want to solve system of equations for each value of a.

For a=3, (x,y)=(4,7), and for a=5, (x,y)=(6,11).

I solve it in a loop:

using NLsolve

function f!(F, x, a)

F[1] =a+x[1]-x[2]

F[2] =2*x[1]-1-x[2]

end

K=zeros(2, length(a))

initial_x=[ 0.1; 0.2]

a=[3.0; 5.0]

for i=1:length(a)

res=nlsolve((F,x) -> f!(F, x, a[i]), initial_x)

K[:,i]=res.zero

end

Is there any smart way to avoid looping?

Also, I would appreciate if you can explain the helper function `n_ary`

.

Thank you.