FMUTIL  0.1
Fortran Miscellaneous UTILities
rootfinding Module Reference

RootFinding Module. More...

Data Types

interface  func
 Interface of the function whose root needs to be computed. More...
 

Functions/Subroutines

subroutine polyroots (c, r, error, BalanceOn)
 Computes the complex roots of the given polynomial. More...
 
pure subroutine root (a, b, ya, yb, tol, f, x, fx, niter, error)
 Subroutine for computing the root using Brent algorithm. More...
 

Variables

integer, parameter max_iterations = 50
 Max iterations for all the root-finding. More...
 

Detailed Description

RootFinding Module.

This module provides functions for root-finding of polynomials by solving associated eigenvalue problems and nonlinear equations using algorithms like Brent's Algorithm.

Author
Bharat Mahajan
Date
Created: 07/31/2019

Function/Subroutine Documentation

◆ polyroots()

subroutine rootfinding::polyroots ( complex(wp), dimension(1:), intent(in)  c,
complex(wp), dimension(:), intent(out), allocatable  r,
integer, intent(out)  error,
logical, intent(in), optional  BalanceOn 
)

Computes the complex roots of the given polynomial.

PolyRoots finds the roots of the polynomial defined by complex coefficients given in array "c" (c(1) is the highest degree coeff.). It forms the companion matrix and then solves its eigenvalues using LAPACk routines from Intel MKL library. The algorithm is same as that used by MATLAB's "roots" command. References:

  1. https://blogs.mathworks.com/cleve/2016/06/27/19-dubious-ways-to-compute-the-zeros-of-a-polynomial/
  2. Math77: http://www.netlib.org/math/docpdf/ch07-01.pdf
    Parameters
    [in]cComplex coefficients of the polynomial defined by p(x) = c(1)*x^n + ... + c(n)*x + c(n+1)
    [out]rComplex roots array
    [out]errorError status returned to the user. "0" : Success, valid results in "r" "-1": Error, input coefficients array has length less than two "-2": Error, all the coefficients are zero "-3": Error, companion matrix balancing failed "-4": Error, LAPACK routine failed to compute eigenvalues
    [in]balanceonIf True, then the companion matrix is balanced first before finding its eigenvalues, otherwise not. Default is True. It may produce inaccurate results in case of very poorly-scaled matrices.
Remarks
return if input coefficient array is empty
Return if all coefficients are zero
Leading zeros are thrown away while the trailing zero coefficients are remembered by introducing roots at zero.

Definition at line 66 of file rootfinding.f90.

References fmutilbase::inf.

◆ root()

pure subroutine rootfinding::root ( real(wp), intent(in)  a,
real(wp), intent(in)  b,
real(wp), intent(in)  ya,
real(wp), intent(in)  yb,
real(wp), intent(in)  tol,
procedure(func f,
real(wp), intent(out)  x,
real(wp), intent(out)  fx,
integer, intent(out)  niter,
integer, intent(out)  error 
)

Subroutine for computing the root using Brent algorithm.

For details on the algorithm, see Numerical receipes in C book at https://www2.units.it/ipl/students_area/imm2/files/Numerical_Recipes.pdf

Parameters
[in]aLower bound on the root
[in]bUpper bound on the root
[in]yaf(a)
[in]ybf(b)
[in]toltolerance
ffunction
[out]xroot
[out]fxvalue at root
[out]niterno. of iterations
[out]errorError status returned to the user. "0" means root has been found. "1" means provided bounds do not contain the root, i.e., root is not bracketed. "2" means maximum number of interations reached.

Definition at line 208 of file rootfinding.f90.

References max_iterations.

Variable Documentation

◆ max_iterations

integer, parameter rootfinding::max_iterations = 50

Max iterations for all the root-finding.

Definition at line 42 of file rootfinding.f90.

Referenced by root().