# Nonlinear equations algorithm - Newton method

Some time ago I posted a question regarding the simple case of finding the intersection point when I have only two functions, and with your help I found an answer.

It was this case:

1. $f(x) = a + \dfrac{1}{bc} (x-x_0)$
2. $g(x) =\ln\dfrac{\sqrt{\dfrac{2dx}{c}+1}-1}{d} + {\sqrt{\dfrac{2dx}{c}+1}-1}$

where $a$, $b$, $c$, $d$, $x_0$ were known. As known, my functions will intersect at the point where $f(x) = g(x)$, or $f(x) - g(x) = 0$. Using the substitution $t=\dfrac{2dx}{c}+1$, I rewrote the formula, limited t to an interval to become only real solutions and with Newton-Raphson and a good initial guess (through Taylor approximation) became the awaited results.

Now, the formulas for the functions get more complex for the case that there are more than two components in the equation.

$$f_i(x) = a + \dfrac{1}{bc} (x-x_0)$$ $$g_i(x,y)= \ln{y_i} + \ln\dfrac{\sqrt{\dfrac{2dx}{c}+1}-1}{d} + 2*\dfrac{\sqrt{\dfrac{2dx}{c}+1}-1}{d} * \sum_{j=1}^n y_jd_j$$

where d is now a mixed term and $i=1:n$. $$d = \sum_{i=1}^n \sum_{j=1}^n y_i y_j d_ij$$ and the sum of

$$\sum_{k=1}^n y_k = 1$$

$y1 = 1 - y2$ in this case.

where $a$, $b$, $c$, $d_ii$, $d_ij$, $d_jj$, $x_0$, $n$, are known.

This time I take two components (n=2), 4 equations and two equations for finding the root - two function differences ($f1 - g1 = 0$, $f2 - g2 = 0$, . I used multivariate Newton-Raphson and once again, with good initial guesses, I found the expected x and y. To move farther in the right direction, I need a little bit of your help.

My first question is regarding the initial guess. Good guesses were found with plotting the functions and knowing something about the awaited results. The goal is now to write a stable program in Fortran that will converge to the solution (when an intersection point is there), although the iteration initial guess would be farther than the awaited result. I know that for the second case, y is defined from 0 to 1, and in the case that d is negative $t=\dfrac{2dx}{c}+1$ would also go from 0 to 1. Let's say I would make an initial guess for x and y for which the solver would converge differently than excepted, then I would have to have some "back-up" case where a new initialization with smaller increments (let's say 0.5 times from the first initialization) would be started with new initial values, and here I would ask for a suggestion how to make this back-up case meaningful.

I tried also Levenberg-Marquardt in Matlab as a separate function, but in this case it had the same problems with initial guesses not too close to the solution, and for programming the same in Fortran it would be too complicated.

One idea was to find a difference vector for the function values going for a pre-defined value of the and to see at which points the function values come near to 0, and then use this points as initial guesses. For the first case with finding only one variable it could make sense, but for the second case the program would have to evaluate the function values dependent on two variables to find a good guess, what seems like too much work, although the computation time is not a problem.

Another question is about propagation of errors. Let's look at the first case in my question and I know that f(x) = g(x), and that two variables a and c have uncertainties. I would like to know how to find the uncertainty in x at the end of the solution, because in this case I couldn't use the formula for error propagation using the total derivative of x.

I would really appreciate your help and your tips and I hope that I wrote in the way that you could understand me. Thank you!

• Why do you write $f_i$ but there is nothing dependent on $i$? – mvw Apr 27 '16 at 20:33
• I know that it isn't the correct way, but I wanted to make the functions "better" visible to show that there are 4 equations. – denis0n Apr 28 '16 at 6:43