Return the polished (refined) root of a polynomial of arbitrary degree specified by its coefficients coef
.
More...
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.
-
If
coef is of type complex , then root must be of the same type and kind as coef .
-
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 ,
-
type
complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
-
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 .
-
A positive non-zero value indicates successful convergence within
niter number of iterations.
-
A negative non-zero value indicates convergence failure within
abs(niter) number of iterations.
-
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 ⛓
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 ⛓
10 type(display_type) :: disp
11 integer(IK) :: niter, iroot
16 real(TKG),
parameter :: noise
= sqrt(
epsilon(
0._TKG))
17 complex(TKG),
allocatable :: root(:)
18 real(TKG),
allocatable :: coef(:)
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)")
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.'
28 call disp%show(
"root = root + (noise, noise)")
29 root
= root
+ (noise, noise)
32 do iroot
= 1,
size(root)
37 call disp%show(
"call setPolyRootPolished(root(iroot), niter, coef)")
41 call disp%show(
"if (0 < niter) call disp%show(root(iroot)) ! polished")
42 if (
0 < niter)
call disp%show(root(iroot))
49 real(TKG),
parameter :: noise
= sqrt(
epsilon(
0._TKG))
50 complex(TKG),
allocatable :: coef(:), root(:)
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)")
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.'
60 call disp%show(
"root = root + (noise, noise)")
61 root
= root
+ (noise, noise)
64 do iroot
= 1,
size(root)
69 call disp%show(
"call setPolyRootPolished(root(iroot), niter, coef)")
73 call disp%show(
"if (0 < niter) call disp%show(root(iroot)) ! polished")
74 if (
0 < niter)
call disp%show(root(iroot))
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
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...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
2coef
= [
real(TKG) ::
-4,
1,
-4,
1]
4if (
size(root)
== 0_IK)
error stop 'no roots could be found.'
6(
+3.99999999999999999999999999999999769,
+0.00000000000000000000000000000000000), (
+0.481482486096808963263994485646231830E-33,
+1.00000000000000000000000000000000019), (
+0.481482486096808963263994485646231830E-33,
-1.00000000000000000000000000000000019)
7root
= root
+ (noise, noise)
9(
+4.00000000000000001387778780781445444,
+0.138777878078144567552953958511352539E-16), (
+0.138777878078144572367778819479442172E-16,
+1.00000000000000001387778780781445695), (
+0.138777878078144572367778819479442172E-16,
-0.999999999999999986122212192185543437)
13(
+4.00000000000000001387778780781445444,
+0.138777878078144567552953958511352539E-16)
17if (
0 < niter)
call disp%show(root(iroot))
18(
+4.00000000000000000000000000000000000,
-0.267276471009219564614053646715148188E-50)
22(
+0.138777878078144572367778819479442172E-16,
+1.00000000000000001387778780781445695)
26if (
0 < niter)
call disp%show(root(iroot))
27(
-0.283224991821652287309754472391031610E-34,
+1.00000000000000000000000000000000019)
31(
+0.138777878078144572367778819479442172E-16,
-0.999999999999999986122212192185543437)
35if (
0 < niter)
call disp%show(root(iroot))
36(
+0.566449983643305055717156761377279526E-35,
-1.00000000000000000000000000000000000)
39coef
= cmplx([
1,
3,
0,
2],
-[
1,
3,
0,
2], TKG)
41if (
size(root)
== 0_IK)
error stop 'no roots could be found.'
43(
+0.156454204739616679002972233441320693,
+1.25436587746244025541937183621617613), (
+0.156454204739616679002972233441320693,
-1.25436587746244025541937183621617574), (
-0.312908409479233358005944466882641627,
+0.00000000000000000000000000000000000)
44root
= root
+ (noise, noise)
46(
+0.156454204739616692880760041255777448,
+1.25436587746244026929715964403063288), (
+0.156454204739616692880760041255777448,
-1.25436587746244024154158402840171899), (
-0.312908409479233344128156659068184871,
+0.138777878078144567552953958511352539E-16)
50(
+0.156454204739616692880760041255777448,
+1.25436587746244026929715964403063288)
54if (
0 < niter)
call disp%show(root(iroot))
55(
+0.156454204739616679002972233441320813,
+1.25436587746244025541937183621617574)
59(
+0.156454204739616692880760041255777448,
-1.25436587746244024154158402840171899)
63if (
0 < niter)
call disp%show(root(iroot))
64(
+0.156454204739616679002972233441320837,
-1.25436587746244025541937183621617574)
68(
-0.312908409479233344128156659068184871,
+0.138777878078144567552953958511352539E-16)
72if (
0 < niter)
call disp%show(root(iroot))
73(
-0.312908409479233358005944466882641675,
+0.185194752467248263059987587374008254E-36)
- 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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- Author:
- Amir Shahmoradi, Oct 16, 2009, 11:14 AM, Michigan
Definition at line 5290 of file pm_polynomial.F90.