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

Defines a solver based upon Brent's method for solving an equation of one variable without using derivatives. More...

Inheritance diagram for nonlin_solve::brent_solver:
nonlin_core::equation_solver_1var

Public Member Functions

procedure, public solve brent_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 Brent's method for solving an equation of one variable without using derivatives.

Definition at line 398 of file nonlin_solve.f90.

Member Function/Subroutine Documentation

◆ solve()

procedure, public nonlin_solve::brent_solver::solve
virtual

Solves the equation.

Syntax
subroutine solve(class(brent_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
The following code provides an example of how to solve an equation of one variable using Brent's method.
program main
type(fcn1var_helper) :: obj
procedure(fcn1var), pointer :: fcn
type(brent_solver) :: solver
real(real64) :: x, f
type(value_pair) :: limits
! Define the solution limits
limits%x1 = 1.5d0
limits%x2 = 5.0d0
! Define the function
fcn => fcn1
call obj%set_fcn(fcn)
! Solve the equation
call solver%solve(obj, x, limits, f)
! Print the output and the residual:
print '(AF5.3)', "The solution: ", x
print '(AE9.3)', "The residual: ", f
contains
! 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
Describes a function of one variable.
nonlin_core
nonlin_solve
Defines a type capable of encapsulating an equation of one variable of the form: f(x) = 0.
Defines a pair of numeric values.
Defines a solver based upon Brent's method for solving an equation of one variable without using deri...
The above program returns the following results.
The solution: 3.142
The residual: -.751E-11
See Also
  • Wikipedia
  • Numerical Recipes
  • R.P. Brent, "Algorithms for Minimization without Derivatives," Dover Publications, January 2002. ISBN 0-486-41998-3. Further information available here.

Implements nonlin_core::equation_solver_1var.

Definition at line 479 of file nonlin_solve.f90.


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