I have a set of N nonlinear equations, $F_i(x_i,p_i) = 0$ in N unknowns, $x_i, i=1,N$. These equations also depend on a set of parameters, $p_i, i=1,P$. Currently I am solving the equations for a fixed set of parameter values, $p_i = p_i^*$ using a Newton scheme. This scheme minimizes the sum of the squares of the residuals, $R = \frac{1}{2} (F_i)^2$
Clearly the minimum found here needs to be as close to zero as possible so that all the equations are satisfied. Now I want to add an optimization level on to this solution, where I have an objective function $G(x_i,p_i)$ which I want to minimize for varying some of the $p_i, i=1,Q$ where $Q\le P$.
Obviously I can just treat the first solution as a function evaluation for the optimizer, however this is not efficient, being an iteration loop within an iteration loop. What I would like to do is solve the entire system using one combined Newton scheme. My question is how do I do this?
I could just add the objective function G to R and minimize the sum, however this may minimize the sum, but not each individually, specifically R which must minimize to zero.