ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_polynomial::setPolyRootPolished Interface Reference

Return the polished (refined) root of a polynomial of arbitrary degree specified by its coefficients coef.
More...

Detailed Description

Return the polished (refined) root of a polynomial of arbitrary degree specified by its coefficients coef.

The procedures of this generic interface uses the Laguerre root polishing method to refine the root of a polynomial of arbitrary degree.
See the documentation of pm_polynomial for details of the root-finding method.

Parameters
[in,out]root: The input/output scalar containing the initial guess for the polynomial root.
  1. If coef is of type complex, then root must be of the same type and kind as coef.
  2. If coef is of type real, then root can be either real or complex of the same kind as coef.
On output, this argument will contain the refined (polished) root of the polynomial \(P\) such that \(P(\ms{root}) = 0\).
[in]coef: The input contiguous vector of size at least 2,
  1. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
  2. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the coefficients of the polynomial in the order of increasing power.
By definition, the degree of the polynomial is size(coef) - 1.
[out]niter: The output scalar of type integer of default kind IK, containing the total number of iterations performed to polish the input root.
  1. A positive non-zero value indicates successful convergence within niter number of iterations.
  2. A negative non-zero value indicates convergence failure within abs(niter) number of iterations.
  3. A zero value indicates the error condition size(coef) < 2 has occurred (i.e., when the input polynomial is a constant).
The value of this output argument must always be inspected before using the output root.


Possible calling interfaces

call setPolyRootPolished(root, niter, coef(:))
Return the polished (refined) root of a polynomial of arbitrary degree specified by its coefficients ...
This module contains procedures and generic interfaces for performing various mathematical operations...
Warning
The condition 1 < size(coef) must hold for the corresponding input arguments.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
It is crucial to keep in mind that computers use a fixed number of binary digits to represent floating-point numbers.
As such polynomials of high degree can be problematic for root-finding algorithms.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
See also
getRoot
setRoot
getPolyRoot
setPolyRoot


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK, RKH
6 use pm_io, only: display_type
7
8 implicit none
9
10 type(display_type) :: disp
11 integer(IK) :: niter, iroot
12 disp = display_type(file = "main.out.F90")
13
14 block
15 use pm_kind, only: TKG => RKH ! all processor kinds are supported.
16 real(TKG), parameter :: noise = sqrt(epsilon(0._TKG))
17 complex(TKG), allocatable :: root(:)
18 real(TKG), allocatable :: coef(:)
19 call disp%skip()
20 call disp%show("coef = [real(TKG) :: -4, 1, -4, 1]")
21 coef = [real(TKG) :: -4, 1, -4, 1]
22 call disp%show("root = getPolyRoot(coef)")
23 root = getPolyRoot(coef)
24 call disp%show("if (size(root) == 0_IK) error stop 'no roots could be found.'")
25 if (size(root) == 0_IK) error stop 'no roots could be found.'
26 call disp%show("root")
27 call disp%show( root )
28 call disp%show("root = root + (noise, noise)")
29 root = root + (noise, noise)
30 call disp%show("root")
31 call disp%show( root )
32 do iroot = 1, size(root)
33 call disp%show("iroot")
34 call disp%show( iroot )
35 call disp%show("root(iroot)")
36 call disp%show( root(iroot) )
37 call disp%show("call setPolyRootPolished(root(iroot), niter, coef)")
38 call setPolyRootPolished(root(iroot), niter, coef)
39 call disp%show("niter")
40 call disp%show( niter )
41 call disp%show("if (0 < niter) call disp%show(root(iroot)) ! polished")
42 if (0 < niter) call disp%show(root(iroot)) ! polished
43 end do
44 call disp%skip()
45 end block
46
47 block
48 use pm_kind, only: TKG => RKH ! all processor kinds are supported.
49 real(TKG), parameter :: noise = sqrt(epsilon(0._TKG))
50 complex(TKG), allocatable :: coef(:), root(:)
51 call disp%skip()
52 call disp%show("coef = cmplx([1, 3, 0, 2], -[1, 3, 0, 2], TKG)")
53 coef = cmplx([1, 3, 0, 2], -[1, 3, 0, 2], TKG)
54 call disp%show("root = getPolyRoot(coef)")
55 root = getPolyRoot(coef)
56 call disp%show("if (size(root) == 0_IK) error stop 'no roots could be found.'")
57 if (size(root) == 0_IK) error stop 'no roots could be found.'
58 call disp%show("root")
59 call disp%show( root )
60 call disp%show("root = root + (noise, noise)")
61 root = root + (noise, noise)
62 call disp%show("root")
63 call disp%show( root )
64 do iroot = 1, size(root)
65 call disp%show("iroot")
66 call disp%show( iroot )
67 call disp%show("root(iroot)")
68 call disp%show( root(iroot) )
69 call disp%show("call setPolyRootPolished(root(iroot), niter, coef)")
70 call setPolyRootPolished(root(iroot), niter, coef)
71 call disp%show("niter")
72 call disp%show( niter )
73 call disp%show("if (0 < niter) call disp%show(root(iroot)) ! polished")
74 if (0 < niter) call disp%show(root(iroot)) ! polished
75 end do
76 call disp%skip()
77 end block
78
79end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return the roots of a polynomial of arbitrary degree specified by its coefficients coef.
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2coef = [real(TKG) :: -4, 1, -4, 1]
3root = getPolyRoot(coef)
4if (size(root) == 0_IK) error stop 'no roots could be found.'
5root
6(+3.99999999999999999999999999999999769, +0.00000000000000000000000000000000000), (+0.481482486096808963263994485646231830E-33, +1.00000000000000000000000000000000019), (+0.481482486096808963263994485646231830E-33, -1.00000000000000000000000000000000019)
7root = root + (noise, noise)
8root
9(+4.00000000000000001387778780781445444, +0.138777878078144567552953958511352539E-16), (+0.138777878078144572367778819479442172E-16, +1.00000000000000001387778780781445695), (+0.138777878078144572367778819479442172E-16, -0.999999999999999986122212192185543437)
10iroot
11+1
12root(iroot)
13(+4.00000000000000001387778780781445444, +0.138777878078144567552953958511352539E-16)
14call setPolyRootPolished(root(iroot), niter, coef)
15niter
16+2
17if (0 < niter) call disp%show(root(iroot)) ! polished
18(+4.00000000000000000000000000000000000, -0.267276471009219564614053646715148188E-50)
19iroot
20+2
21root(iroot)
22(+0.138777878078144572367778819479442172E-16, +1.00000000000000001387778780781445695)
23call setPolyRootPolished(root(iroot), niter, coef)
24niter
25+2
26if (0 < niter) call disp%show(root(iroot)) ! polished
27(-0.283224991821652287309754472391031610E-34, +1.00000000000000000000000000000000019)
28iroot
29+3
30root(iroot)
31(+0.138777878078144572367778819479442172E-16, -0.999999999999999986122212192185543437)
32call setPolyRootPolished(root(iroot), niter, coef)
33niter
34+2
35if (0 < niter) call disp%show(root(iroot)) ! polished
36(+0.566449983643305055717156761377279526E-35, -1.00000000000000000000000000000000000)
37
38
39coef = cmplx([1, 3, 0, 2], -[1, 3, 0, 2], TKG)
40root = getPolyRoot(coef)
41if (size(root) == 0_IK) error stop 'no roots could be found.'
42root
43(+0.156454204739616679002972233441320693, +1.25436587746244025541937183621617613), (+0.156454204739616679002972233441320693, -1.25436587746244025541937183621617574), (-0.312908409479233358005944466882641627, +0.00000000000000000000000000000000000)
44root = root + (noise, noise)
45root
46(+0.156454204739616692880760041255777448, +1.25436587746244026929715964403063288), (+0.156454204739616692880760041255777448, -1.25436587746244024154158402840171899), (-0.312908409479233344128156659068184871, +0.138777878078144567552953958511352539E-16)
47iroot
48+1
49root(iroot)
50(+0.156454204739616692880760041255777448, +1.25436587746244026929715964403063288)
51call setPolyRootPolished(root(iroot), niter, coef)
52niter
53+2
54if (0 < niter) call disp%show(root(iroot)) ! polished
55(+0.156454204739616679002972233441320813, +1.25436587746244025541937183621617574)
56iroot
57+2
58root(iroot)
59(+0.156454204739616692880760041255777448, -1.25436587746244024154158402840171899)
60call setPolyRootPolished(root(iroot), niter, coef)
61niter
62+2
63if (0 < niter) call disp%show(root(iroot)) ! polished
64(+0.156454204739616679002972233441320837, -1.25436587746244025541937183621617574)
65iroot
66+3
67root(iroot)
68(-0.312908409479233344128156659068184871, +0.138777878078144567552953958511352539E-16)
69call setPolyRootPolished(root(iroot), niter, coef)
70niter
71+2
72if (0 < niter) call disp%show(root(iroot)) ! polished
73(-0.312908409479233358005944466882641675, +0.185194752467248263059987587374008254E-36)
74
75
Test:
test_pm_polynomial
Todo:
Normal Priority: An optional reltol may be added in the future to allow control over the error in the refined root.


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Oct 16, 2009, 11:14 AM, Michigan

Definition at line 5290 of file pm_polynomial.F90.


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