Nonlinear Solver Lab

Getting Started

  • This manual briefly explains the nonlinear multi-dimensional root-finding, W4 method. If you need much information, please see our reference.

Starter Guide for W4

  1. Nonlinear problem we want to solve
  2. The Newton-Raphson method
  3. The W4 methods
  4. How to call the W4 function

1. Nonlinear problem we want to solve

In general, the system of nonlinear equations is given as $\textbf{F}(\textbf{x})=\textbf{0}$.
For example, if the number of variables is three, $\textbf{F}$ has three components, which yields to
$f_{1}(x_1,x_2,x_3)=0$,
$f_{2}(x_1,x_2,x_3)=0$,
$f_{3}(x_1,x_2,x_3)=0$.

2. The Newton-Raphson method

To solve the system of nonlinear equations, that is, $\textbf{F}(\textbf{x})=\textbf{0}$, we linearize the system around the solution $\textbf{x}^{*}=\textbf{x}+\Delta\textbf{x}$,
$\textbf{F}(\textbf{x}^{*}) \sim \textbf{F}(\textbf{x}) +J\Delta\textbf{x}$
where $J = \frac{\partial \textbf{F}}{\partial\textbf{x}}$ is called Jacobian matrix.

Since $\textbf{F}(\textbf{x}^{*})=\textbf{0}$, the Newton-Raphson method defines the increment computed by
$\textbf{x}^{n+1} = \textbf{x}^{n} -J^{-1}\textbf{F}(\textbf{x}^n)$.

This Newton-Raphson map is regarded as the discretized form of the following differential equation with the time interval $\Delta \tau=1$:
$\dot{\textbf{x}} = -J^{-1}\textbf{F}(\textbf{x})$

3. The W4 method

The W4 method adds the second-order time derivative into the continuous form of the Newton method as follows:
$\ddot{\textbf{x}} +2\dot{\textbf{x}} -\dot{X}X^{-1}\dot{\textbf{x}} +XY\textbf{F}=\textbf{0}$.

In short, introducing a new degree of freedom that corresponds to the choice of the matrices $X$ and $Y$, we safely solve the system of nonliear equations.
Usually, it is better to choose the matrix $XY=J^{-1}$, while we still have option to give matrix $X$.

The second-order differential equations can be rewritten two first-order differential equations.
Thus, the discretized form of the W4 method is given
$\textbf{x}^{n+1} = \textbf{x}^{n} +\Delta\tau X\textbf{p}$
$\textbf{p}^{n+1} = (1-2\Delta\tau)\textbf{p}^{n} -\Delta\tau Y\textbf{F}$.

4. How to call the W4 function in Python

The W4 function like w4ul and w4lh has eight arguments: (v,F,Fa,J,ini,dt,itermax,errmax).

  • v :: variables (n-dimensional numpy array)
  • F :: n-equations
  • Fa :: absolute values of n-equations (for stopping criterion)
  • J :: Jacobian matrix defined from F
  • ini:: initial guess for v
  • dt :: time interval
  • itermax:: maximum step for iteration loop
  • errmax :: criterion to stop iteration

(1) Define your nonlinear equations

First of all, you have to determine the dimension of your system of equations, dim, which also corresponds to the number of variables.
You can add your nonlinear equations in the Sympy style.
In this case, variables are defined from x[0] to x[dim-1].

f = [];
f.append( 10*(x[1]-x[0]**2) );
f.append( 1 - x[0] );

(2) Set up numpy variables from sympy variables by calc_source function

Automatically, you give necessary numpy variables from the above f.

vn, Fn, Fan, Jacn = calc_source(x,f);

(3) Choose your initial condition for v

Initial guess is given in the numpy style.

vini = np.array([]);
vini = np.append(vini, 1.2);
vini = np.append(vini, 1.0);


(4) Call the w4 function

Finally, you can start the iteration from the initial guess.
If err and iter are less than your criteria, i.e., errmax and itermax, your problem is solved.
The final answer should be in vans in this case.

vans, iter, err = w4ul(vn,Fn,Fan,Jacn,vini,dtau,itermax,errmax);
In [ ]: