Find a root of a dense nonlinear system.
Solve with safeguarded Newton and LM fallback. Newton steps use Armijo backtracking; ill-conditioned Jacobians trigger Levenberg-Marquardt regularization. Diagnostics are returned even when the iteration does not converge.
call newton(residual_and_jacobian, x, settings, result)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| procedure(to_solve) | :: | sub |
User-supplied residual/Jacobian routine (matches to_solve interface) |
|||
| real(kind=pr), | intent(inout) | :: | x(:) |
[in] Initial guess, length n |
||
| type(newton_settings), | intent(in), | optional | :: | settings |
Solver configuration; defaults are used for any absent fields |
|
| type(newton_result), | intent(out), | optional | :: | result |
Diagnostic output: status, iteration count, norms, history |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| real(kind=pr), | private, | allocatable | :: | F(:) |
Residual at current x, size n |
||
| real(kind=pr), | private, | allocatable | :: | F_new(:) |
Residual at trial point x+t*dX |
||
| real(kind=pr), | private, | allocatable | :: | J(:,:) |
Jacobian at current x, shape (n,n) |
||
| real(kind=pr), | private, | allocatable | :: | J_new(:,:) |
Jacobian at trial point x+t*dX |
||
| real(kind=pr), | private, | allocatable | :: | X_old(:) |
x saved before applying the step |
||
| real(kind=pr), | private | :: | cond_est |
Estimated cond(J) from dgecon |
|||
| logical, | private | :: | converged |
.true. when a convergence criterion is met |
|||
| real(kind=pr), | private, | allocatable | :: | dX(:) |
Newton (or LM) step, size n |
||
| real(kind=pr), | private | :: | dx_norm |
||dX||_inf of current Newton step |
|||
| real(kind=pr), | private | :: | dx_norm_prev |
||dX||_inf from previous iteration |
|||
| real(kind=pr), | private | :: | f_norm |
||F(x)||_inf at current iterate |
|||
| real(kind=pr), | private | :: | f_norm_new |
||F(x + t*dX)||_inf after line search |
|||
| real(kind=pr), | private, | allocatable | :: | hist_buf(:) |
Scratch buffer for f_history |
||
| integer, | private | :: | its |
Current iteration counter |
|||
| real(kind=pr), | private | :: | jscale |
||J||_F^2/n; scale for lambda floor/ceiling |
|||
| real(kind=pr), | private | :: | lambda |
LM regularization parameter (absolute) |
|||
| logical, | private | :: | ls_failed |
.true. when line search returned failed=.true. |
|||
| integer, | private | :: | n |
Problem size (number of unknowns) |
|||
| type(newton_result), | private | :: | res |
Internal result accumulator |
|||
| type(newton_settings), | private | :: | s |
Active settings (defaults or user) |
|||
| logical, | private | :: | small_step |
.true. when accepted t is numerically tiny |
|||
| integer, | private | :: | stag_count |
Consecutive stagnant iterations |
|||
| logical, | private | :: | stagnated |
.true. when stag_count >= stagnation_nits |
|||
| real(kind=pr), | private | :: | t |
Current line-search step length in (0,1] |