fzero - fabiankindermann/ce-fortran GitHub Wiki
subroutine fzero(x, funcv, check_return)
This subroutine solves a non-linear equation or equation system, meaning that it searches for a value such that
, with
.
can be either 1 or greater than one, in which case
is either a scalar or a vector.
-
real*8 :: xorreal*8 :: x(:)
xcan be either a scalar or a one-dimensional array, indicating whetherfzeroshould solve a single equation or an equation system. The subroutine will use the values provided inxas starting guess for solving the equation system. Hence, the closerxis to the actual root of the function, the faster and the more reliable will be the rootfinding process.
-
function :: funcv
The inputfuncvis the name of a function that provides the non-linear equation or equation system that should be solved byfzero. Note that this function needs to be stored somewhere in a module and can not be an element of thecontainsstatement the main program. Ifxis a scalar, this function must follow exactly the calling conventions:function funcv(p) implicit none real*8, intent(in) :: p real*8 :: funcv [......] end function funcv
If
x(:)is a one-dimensional array we havefunction funcv(p) implicit none real*8, intent(in) :: p(:) real*8 :: funcv(size(p, 1)) [......] end function funcv
-
real*8 :: xorreal*8 :: x(:)
Having successfully solved the non-linear equation or equation system, the resulting solutionwill again be stored in the scalar or array
x, such that no additional output argument is needed.xis hence of the typeinout.
-
logical :: check_return
The optional logical scalarcheck_returncan be used as an indicator for whether the root-finding process was successful. If everything went smoothly, thencheck_returnis assigned a value of.false.. If, however, an error occurred throughout the iteration process within the subroutinefzero,check_returnis assigned a value of.true..
- Parts of this routine were copied and adapted from:
- Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). Numerical Recipes in Fortran 90: The Art of Parallel Scientific Computing, 2nd edition. Cambridge: Cambridge Univeristy Press.
- For further reading refer to:
- Broydn, C.G. (1967). Quasi-Newton methods and their application to function minimisation. Mathematics of Computation, 19, 577-593.
- Allen, M.B. & Isaacson, E.L. (1998). Numerical Analysis for Applied Science. Wiley Series in Pure and Applied Mathematics, New York: Wiley.
- This routine is used in the following programs:
prog02_08.f90prog02_14.f90prog03_02.f90prog03_03.f90prog03_04.f90prog03_05.f90prog03_06.f90prog03_07.f90prog04_02.f90prog04_09.f90prog06_01.f90prog06_02.f90prog08_06.f90prog09_01.f90prog09_02.f90prog09_03.f90prog09_04.f90prog09_05.f90prog09_06.f90prog09_07.f90prog09_08.f90prog09_08m.f90prog09_09.f90prog09_09m.f90prog09_10.f90prog09_10m.f90prog10_01.f90prog10_02.f90prog10_03.f90prog10_04.f90prog10_05.f90prog10_06.f90prog11_01.f90prog11_02.f90prog11_03.f90