nonlin 1.5.2
A library that provides routines to compute the solutions to systems of nonlinear equations.
Loading...
Searching...
No Matches
nonlin_core::equation_optimizer Type Referenceabstract

A base class for optimization of an equation of multiple variables. More...

Inheritance diagram for nonlin_core::equation_optimizer:
nonlin_optimize::line_search_optimizer nonlin_optimize::nelder_mead nonlin_optimize::bfgs

Public Member Functions

procedure, public get_max_fcn_evals oe_get_max_eval
 Gets the maximum number of function evaluations allowed.
 
procedure, public set_max_fcn_evals oe_set_max_eval
 Sets the maximum number of function evaluations allowed.
 
procedure, public get_tolerance oe_get_tol
 Gets the tolerance on convergence.
 
procedure, public set_tolerance oe_set_tol
 Sets the tolerance on convergence.
 
procedure, public get_print_status oe_get_print_status
 Gets a logical value determining if iteration status should be printed.
 
procedure, public set_print_status oe_set_print_status
 Sets a logical value determining if iteration status should be printed.
 
procedure(nonlin_optimize_fcn), deferred, pass, public solve nonlin_optimize_fcn
 Optimizes the equation.
 

Public Attributes

real(real64) m_tol = 1.0d-12
 The error tolerance used to determine convergence.
 
logical m_printstatus = .false.
 Set to true to print iteration status; else, false.
 

Private Attributes

integer(int32) m_maxeval = 500
 The maximum number of function evaluations allowed.
 

Detailed Description

A base class for optimization of an equation of multiple variables.

Example
The following example illustrates how to find the minimum of a function of multipler variables by means of the BFGS method.
program example
use iso_fortran_env
implicit none
! Local Variables
type(bfgs) :: solver
type(fcnnvar_helper) :: obj
procedure(fcnnvar), pointer :: fcn
procedure(gradientfcn), pointer :: grad
real(real64) :: x(2), f
! Tell the solver where to find the function
fcn => beale
grad => bealegrad
call obj%set_fcn(fcn, 2)
call obj%set_gradient_fcn(grad)
! Define an initial guess
x = 1.0d0
! Compute the solution
call solver%solve(obj, x, f)
! Display the output
print '(AF7.5AF7.5A)', "Minimum: (", x(1), ", ", x(2), ")"
print '(AE9.3)', "Function Value: ", f
contains
! The Beale function:
! f(x) = (1.5 - x + xy)**2 + (2.25 - x + xy**2)**2 + (2.625 - x + xy**3)**2
! The minimum is at x = 3, y = 0.5, and f(3, 0.5) = 0
function beale(x) result(f)
real(real64), intent(in), dimension(:) :: x
real(real64) :: f
f = (1.5d0 - x(1) + x(1) * x(2))**2 + &
(2.25d0 - x(1) + x(1) * x(2)**2)**2 + &
(2.625d0 - x(1) + x(1) * x(2)**3)**2
end function
! The gradient
subroutine bealegrad(x, g)
real(real64), intent(in), dimension(:) :: x
real(real64), intent(out), dimension(:) :: g
g(1) = 2.0d0 * (x(2)**3 - 1.0d0) * (x(1) * x(2)**3 - x(1) + 2.625d0) + &
2.0d0 * (x(2)**2 - 1.0d0) * (x(1) * x(2)**2 - x(1) + 2.25d0) + &
2.0d0 * (x(2) - 1.0d0) * (x(1) * x(2) - x(1) + 1.5d0)
g(2) = 6.0d0 * x(1) * x(2)**2 * (x(1) * x(2)**3 - x(1) + 2.625d0) + &
4.0d0 * x(1) * x(2) * (x(1) * x(2)**2 - x(1) + 2.25d0) + &
2.0d0 * x(1) * (x(1) * x(2) - x(1) + 1.5d0)
end subroutine
end program
nonlin_core
nonlin_optimize
The above program produces the following output.
Minimum: (3.00000, 0.50000)
Function Value: 0.999E-28

Definition at line 1767 of file nonlin_core.f90.

Member Function/Subroutine Documentation

◆ get_max_fcn_evals()

procedure, public nonlin_core::equation_optimizer::get_max_fcn_evals

Gets the maximum number of function evaluations allowed.

Syntax
pure integer(int32) function get_max_fcn_evals(class(equation_optimizer) this)
Parameters
[in]thisThe equation_optimizer object.
Returns
The maximum number of function evaluations.

Definition at line 1785 of file nonlin_core.f90.

◆ get_print_status()

procedure, public nonlin_core::equation_optimizer::get_print_status

Gets a logical value determining if iteration status should be printed.

Syntax
pure logical get_print_status(class(equation_optimizer) this)
Parameters
[in]thisThe equation_optimizer object.
Returns
True if the iteration status should be printed; else, false.

Definition at line 1826 of file nonlin_core.f90.

◆ get_tolerance()

procedure, public nonlin_core::equation_optimizer::get_tolerance

Gets the tolerance on convergence.

Syntax
pure real(real64) function get_tolerance(class(equation_optimizer) this)
Parameters
[in]thisThe equation_optimizer object.
Returns
The convergence tolerance.

Definition at line 1805 of file nonlin_core.f90.

◆ set_max_fcn_evals()

procedure, public nonlin_core::equation_optimizer::set_max_fcn_evals

Sets the maximum number of function evaluations allowed.

Syntax
subroutine set_max_fcn_evals(class(equation_optimizer) this, integer(int32) n)
Parameters
[in,out]thisThe equation_optimizer object.
[in]nThe maximum number of function evaluations.

Definition at line 1795 of file nonlin_core.f90.

◆ set_print_status()

procedure, public nonlin_core::equation_optimizer::set_print_status

Sets a logical value determining if iteration status should be printed.

Syntax
subroutine set_print_status(class(equation_optimizer) this, logical x)
Parameters
[in,out]thisThe equation_optimizer object.
[in]xTrue if the iteration status should be printed; else, false.

Definition at line 1837 of file nonlin_core.f90.

◆ set_tolerance()

procedure, public nonlin_core::equation_optimizer::set_tolerance

Sets the tolerance on convergence.

Syntax
subroutine set_tolerance(class(equation_optimizer) this, real(real64) x)
Parameters
[in,out]thisThe equation_optimizer object.
[in]xThe convergence tolerance.

Definition at line 1815 of file nonlin_core.f90.

◆ solve()

procedure(nonlin_optimize_fcn), deferred, pass, public nonlin_core::equation_optimizer::solve
pure virtual

Optimizes the equation.

Example
See the equation_optimizer type for an example on how to solve a system of equations.

Implemented in nonlin_optimize::bfgs, and nonlin_optimize::nelder_mead.

Definition at line 1843 of file nonlin_core.f90.

Member Data Documentation

◆ m_maxeval

integer(int32) nonlin_core::equation_optimizer::m_maxeval = 500
private

The maximum number of function evaluations allowed.

Definition at line 1770 of file nonlin_core.f90.

◆ m_printstatus

logical nonlin_core::equation_optimizer::m_printstatus = .false.

Set to true to print iteration status; else, false.

Definition at line 1774 of file nonlin_core.f90.

◆ m_tol

real(real64) nonlin_core::equation_optimizer::m_tol = 1.0d-12

The error tolerance used to determine convergence.

Definition at line 1772 of file nonlin_core.f90.


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