function f!(F, x)
F[1] = (x[1] + 3) * (x[2]^3 - 7) + 18
F[2] = sin(x[2] * exp(x[1]) - 1)
F[3] = x[1] + x[2]
return F
end

without knowing F in advance?

My is to program my own non-linear equation solver, so I have to be flexible to program it in a way that works for any size of F. For example, by executing customnlsolver(f!, x0) I need to know what size F has to be able to configure the Jacobian for AD with ForwardDiff.

In your nonlinear-equation solver, just infer the dimension of the problem from the size of the initial guess that the user passes to your solver (not from the function object).

If the number of variables doesnât match the number of equations then you arenât doing root-finding, you are doing optimization (e.g. least-squares), and you will need an objective function that returns a scalar. In that case, you will be computing the gradient, not the Jacobian, and you donât need to know the size of the internal state of your scalar objective function.

Initially I got confused by your wording, but now I see what you mean, that a way to proceed is to minimize the norm of the residuals of the system. Thank you.

In a system F: \mathbb{R}^n \rightarrow \mathbb{R}^n, what are the conditions under which it is better to try to solve F(x)=\vec{0} using root-finding algorithms vs solving the fixed point G(x) = x, with G(x) = F(x) + x?

Rephrasing the question (at the risk of putting my foot in my mouth again), what is a âbetterâ approach (say in terms of accuracy, or speed of convergence), directly solving for the zero of F using a nonlinear solver, or iterating on G until an fixed point is found?

âwhat is a âbetterâ approachâ depends on the characteristics of G. Fixed point iteration can only work if the system is stable, and convergence is only as fast as the stable systemâs dynamics (e.g. eigenvalues of linearized G). Thatâs not an issue for nonlinear solvers, but most will work best if F has a smooth gradient or other known properties. I believe it would take extreme luck for iterations of G to outperform a good nonlinear solver of F, but only you could know.

âIterating on Gâ with fixed-point iterations is a nonlinear solver. So your question still doesnât make much literal sense. But I think you mean, âHow does fixed-point iteration compare to other nonlinear-solver algorithms?â

Fixed-point iteration is one of the least reliable nonlinear-solver algorithms â it only works for contractive maps, and even then is relatively slowly converging compared to e.g. Newtonâs method. The main advantages of a fixed-point iteration are that it is easy to implement (which is nontrivial â computer time is cheaper than programmer time), requires minimal storage (no extraneous vectors or matrices), and doesnât require you to supply a Jacobian matrix.

I would use Newtonâs method as my first choice if you have easy/cheap access to the Jacobian (e.g. via AD). Even without a Jacobian, there are a variety of Jacobian-free algorithms that are probably faster than fixed-point iteration, e.g. Anderson acceleration, the closely related Broydenâs method, or NewtonâKrylov methods (which only require a directional derivative that can be computed by finite differences if needed). These algorithms are more complicated to implement, but thatâs what we have libraries for.