nonlin 1.5.2
A library that provides routines to compute the solutions to systems of nonlinear equations.
Loading...
Searching...
No Matches
nonlin_solve::newton_1var_solver Type Reference

Defines a solver based upon Newtons's method for solving an equation of one variable. The algorithm uses a bisection method in conjunction with Newton's method in order to keep bounds upon the Newton iterations. More...

Inheritance diagram for nonlin_solve::newton_1var_solver:
nonlin_core::equation_solver_1var

Public Member Functions

procedure, public solve newt1var_solve
 Solves the equation.
 
- Public Member Functions inherited from nonlin_core::equation_solver_1var
procedure, public get_max_fcn_evals es1_get_max_eval
 Gets the maximum number of function evaluations allowed during a single solve.
 
procedure, public set_max_fcn_evals es1_set_max_eval
 Sets the maximum number of function evaluations allowed during a single solve.
 
procedure, public get_fcn_tolerance es1_get_fcn_tol
 Gets the convergence on function value tolerance.
 
procedure, public set_fcn_tolerance es1_set_fcn_tol
 Sets the convergence on function value tolerance.
 
procedure, public get_var_tolerance es1_get_var_tol
 Gets the convergence on change in variable tolerance.
 
procedure, public set_var_tolerance es1_set_var_tol
 Sets the convergence on change in variable tolerance.
 
procedure, public get_print_status es1_get_print_status
 Gets a logical value determining if iteration status should be printed.
 
procedure, public set_print_status es1_set_print_status
 Sets a logical value determining if iteration status should be printed.
 
procedure, public get_diff_tolerance es1_get_diff_tol
 Gets the convergence on slope of the function (derivative) tolerance.
 
procedure, public set_diff_tolerance es1_set_diff_tol
 Sets the convergence on slope of the function (derivative) tolerance.
 

Additional Inherited Members

- Public Attributes inherited from nonlin_core::equation_solver_1var
real(real64) m_fcntol = 1.0d-8
 The convergence criteria on function value.
 
real(real64) m_xtol = 1.0d-12
 The convergence criteria on change in variable value.
 
real(real64) m_difftol = 1.0d-12
 The convergence criteria on the slope of the function (derivative)
 
logical m_printstatus = .false.
 Set to true to print iteration status; else, false.
 

Detailed Description

Defines a solver based upon Newtons's method for solving an equation of one variable. The algorithm uses a bisection method in conjunction with Newton's method in order to keep bounds upon the Newton iterations.

Definition at line 502 of file nonlin_solve.f90.

Member Function/Subroutine Documentation

◆ solve()

procedure, public nonlin_solve::newton_1var_solver::solve
virtual

Solves the equation.

Syntax
subroutine solve(class(newton_1var_solver) this, class(fcn1var_helper) fcn, real(real64) x, type(value_pair) lim, optional real(real64) f, optional type(iteration_behavior) ib, optional class(errors) err)
Parameters
[in,out]thisThe brent_solver object.
[in]fcnThe fcn1var_helper object containing the equation to solve.
[in,out]xA parameter used to return the solution. Notice, any input value will be ignored as this routine relies upon the search limits in lim to provide a starting point.
[in]limA value_pair object defining the search limits.
[out]fAn optional parameter used to return the function residual as computed at x.
[out]ibAn optional output, that if provided, allows the caller to obtain iteration performance statistics.
[out]errAn optional errors-based object that if provided can be used to retrieve information relating to any errors encountered during execution. If not provided, a default implementation of the errors class is used internally to provide error handling. Possible errors and warning messages that may be encountered are as follows.
  • NL_INVALID_OPERATION_ERROR: Occurs if no equations have been defined.
  • NL_INVALID_INPUT_ERROR: Occurs if the number of equations is different than the number of variables.
  • NL_CONVERGENCE_ERROR: Occurs if the algorithm cannot converge within the allowed number of iterations.
Example
program example
use iso_fortran_env
implicit none
! Local variables
type(fcn1var_helper) :: obj
procedure(fcn1var), pointer :: fcn
type(newton_1var_solver) :: solver
real(real64) :: x, f
type(value_pair) :: limits
type(iteration_behavior) :: tracking
! Define the search limits
limits%x1 = 1.5d0
limits%x2 = 5.0d0
! Establish the function
fcn => fcn1
call obj%set_fcn(fcn)
! Solve the equation
call solver%solve(obj, x, limits, f, ib = tracking)
! Print the output and the residual
print '(AF7.5)', "The solution: ", x
print '(AE10.3)', "The residual: ", f
print '(AI0)', "Iterations: ", tracking%iter_count
print '(AI0)', "Function Evaluations: ", tracking%fcn_count
print '(AI0)', "Derivative Evaluations: ", tracking%jacobian_count
print '(AL1)', "Converge on Function Value: ", tracking%converge_on_fcn
print '(AL1)', "Converge on Change in Variable: ", tracking%converge_on_chng
print '(AL1)', "Converge on Derivative: ", tracking%converge_on_zero_diff
contains
! The function:
! f(x) = sin(x) / x, solution: x = n * pi for n = 1, 2, 3, ...
function fcn1(x) result(f)
real(real64), intent(in) :: x
real(real64) :: f
f = sin(x) / x
end function
end program
nonlin_core
nonlin_solve
The above program produces the following output.
The solution: 3.14159
The residual: 0.314E-11
Iterations: 3
Function Evaluations: 7
Derivative Evaluations: 4
Converge on Function Value: T
Converge on Change in Variable: F
Converge on Derivative: F

Implements nonlin_core::equation_solver_1var.

Definition at line 591 of file nonlin_solve.f90.


The documentation for this type was generated from the following file: