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

Defines a type capable of encapsulating an equation of one variable of the form: f(x) = 0. More...

Public Member Functions

procedure, public fcn f1h_fcn
 Executes the routine containing the function to evaluate.
 
procedure, public is_fcn_defined f1h_is_fcn_defined
 Tests if the pointer to the function containing the equation to solve has been assigned.
 
procedure, public set_fcn f1h_set_fcn
 Establishes a pointer to the routine containing the equations to solve.
 
procedure, public is_derivative_defined f1h_is_diff_defined
 Tests if the pointer to the function containing the derivative of the function to solve is defined.
 
procedure, public diff f1h_diff_fcn
 Computes the derivative of the function. If a routine for computing the derivative is not defined, the derivative is estimated via finite differences.
 
procedure, public set_diff f1h_set_diff
 

Static Public Attributes

procedure(fcn1var), pointer, nopass m_diff => null()
 A pointer to a function capable of computing the derivative of m_fcn.
 

Static Private Attributes

procedure(fcn1var), pointer, nopass m_fcn => null()
 A pointer to the target fcn1var routine.
 

Detailed Description

Defines a type capable of encapsulating an equation of one variable of the form: f(x) = 0.

Example
The following example illustrates the use of this type to solve an equation using Brent's method.
program example
use iso_fortran_env
implicit none
! Local variables
type(fcn1var_helper) :: obj
procedure(fcn1var), pointer :: fcn
type(brent_solver) :: solver
real(real64) :: x, f
type(value_pair) :: limits
! 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)
! Print the output and the residual
print '(AF7.5)', "The solution: ", x
print '(AE10.3)', "The residual: ", f
contains
! The function:
! f(x) = sin(x) / x, solution: x = x * 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.751E-11

Definition at line 682 of file nonlin_core.f90.

Member Function/Subroutine Documentation

◆ diff()

procedure, public nonlin_core::fcn1var_helper::diff

Computes the derivative of the function. If a routine for computing the derivative is not defined, the derivative is estimated via finite differences.

Syntax
real(real64) function derivative(class(fcn1var_helper) this, real(real64) x, optional real(real64) f)
Parameters
[in]thisThe fcn1var_helper object.
[in]xThe value of the independent variable at which the derivative is to be computed.
[in]fAn optional input specifying the function value at x. If supplied, and the derivative is being estimated numerically, the function will not be evaluated at x.

Definition at line 796 of file nonlin_core.f90.

◆ fcn()

procedure, public nonlin_core::fcn1var_helper::fcn

Executes the routine containing the function to evaluate.

Syntax
real(real64) function fcn(class(fcn1var_helper) this, real(real64) x)
Parameters
[in]thisThe fcn1var_helper object.
[in]xThe value of the independent variable at which the function should be evaluated.
Returns
The value of the function at x.

Definition at line 700 of file nonlin_core.f90.

◆ is_derivative_defined()

procedure, public nonlin_core::fcn1var_helper::is_derivative_defined

Tests if the pointer to the function containing the derivative of the function to solve is defined.

Syntax
logical function is_derivative_defined(class(fcn1var_helper) this)
Parameters
[in]thisThe fcn1var_helper object.
Returns
Returns true if the pointer has been assigned; else, false.

Definition at line 782 of file nonlin_core.f90.

◆ is_fcn_defined()

procedure, public nonlin_core::fcn1var_helper::is_fcn_defined

Tests if the pointer to the function containing the equation to solve has been assigned.

Syntax
logical function is_fcn_defined(class(fcn1var_helper) this)
Parameters
[in]thisThe fcn1var_helper object.
Returns
Returns true if the pointer has been assigned; else, false.

Definition at line 711 of file nonlin_core.f90.

◆ set_diff()

procedure, public nonlin_core::fcn1var_helper::set_diff

Definition at line 806 of file nonlin_core.f90.

◆ set_fcn()

procedure, public nonlin_core::fcn1var_helper::set_fcn

Establishes a pointer to the routine containing the equations to solve.

Syntax
subroutine set_fcn(class(fcn1var_helper) this, procedure(fcn1var) pointer fcn)
Parameters
[in,out]thisThe fcn1var_helper object.
[in]fcnThe function pointer.
Example
The following example illustrates how to use this routine to inform the solver of the function to solve. This particular example utilizes Brent's method to compute the solution.
program example
use iso_fortran_env
implicit none
! Local variables
type(fcn1var_helper) :: obj
procedure(fcn1var), pointer :: fcn
type(brent_solver) :: solver
real(real64) :: x, f
type(value_pair) :: limits
! 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)
! Print the output and the residual
print '(AF7.5)', "The solution: ", x
print '(AE10.3)', "The residual: ", f
contains
! The function:
! f(x) = sin(x) / x, solution: x = x * 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
The above program produces the following output.
The solution: 3.14159
The residual: -0.751E-11

Definition at line 771 of file nonlin_core.f90.

Member Data Documentation

◆ m_diff

procedure(fcn1var), pointer, nopass nonlin_core::fcn1var_helper::m_diff => null()
static

A pointer to a function capable of computing the derivative of m_fcn.

Definition at line 687 of file nonlin_core.f90.

◆ m_fcn

procedure(fcn1var), pointer, nopass nonlin_core::fcn1var_helper::m_fcn => null()
staticprivate

A pointer to the target fcn1var routine.

Definition at line 685 of file nonlin_core.f90.


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