Basic Newton solver.
interface for the function and derivative
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | x | |||
real(kind=wp), | intent(out) | :: | f |
Newton's method for root finding of scalar function f(x)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | x |
initial point (initial guess) |
||
procedure(func) | :: | f |
function f(x) |
|||
procedure(func) | :: | dfdx |
first derivative function f'(x) |
|||
real(kind=wp), | intent(in) | :: | ftol |
convergence tolerance for f(x) |
||
real(kind=wp), | intent(in) | :: | xtol |
convergence tolerance for x |
||
integer, | intent(in) | :: | max_iter |
the maximum number of iterations |
||
real(kind=wp), | intent(out) | :: | xs |
the value where f(x) is zero |
||
real(kind=wp), | intent(out) | :: | fx |
the value of f(x) at the root xs |
||
integer, | intent(out) | :: | iflag |
status flag: 0 : absolute convergence in f 1 : relative convergence in x -1 : Error: derivative is zero -2 : Error: max iterations exceeded |