@@ -35,6 +35,49 @@ Method name | Polynomial type | Coefficients | Roots | Reference
3535[ ` cmplx_roots_gen ` ] ( https://jacobwilliams.github.io/polyroots-fortran/proc/cmplx_roots_gen.html ) | General | complex | complex | [ Skowron & Gould (2012)] ( http://www.astrouw.edu.pl/~jskowron/cmplx_roots_sg/ )
3636[ ` fpml ` ] ( https://jacobwilliams.github.io/polyroots-fortran/proc/fpml.html ) | General | complex | complex | [ Cameron (2019)] ( https://link.springer.com/article/10.1007/s11075-018-0641-9 )
3737
38+ ## Example
39+
40+ An example of using ` polyroots ` to compute the zeros for a 5th order real polynomial $$ P(x) = x^5 + 2x^4 + 3x^3 + 4x^2 + 5x + 6 $$
41+
42+ ``` fortran
43+ program example
44+
45+ use iso_fortran_env
46+ use polyroots_module, wp => polyroots_module_rk
47+
48+ implicit none
49+
50+ integer,parameter :: degree = 5 !! polynomial degree
51+ real(wp),dimension(degree+1) :: p = [1,2,3,4,5,6] !! coefficients
52+
53+ integer :: i !! counter
54+ integer :: istatus !! status code
55+ real(wp),dimension(degree) :: zr !! real components of roots
56+ real(wp),dimension(degree) :: zi !! imaginary components of roots
57+
58+ call polyroots(degree, p, zr, zi, istatus)
59+
60+ write(*,'(A,1x,I3)') 'istatus: ', istatus
61+ write(*, '(*(a22,1x))') 'real part', 'imaginary part'
62+ do i = 1, degree
63+ write(*,'(*(e22.15,1x))') zr(i), zi(i)
64+ end do
65+
66+ end program example
67+ ```
68+
69+ The result is:
70+
71+ ```
72+ istatus: 0
73+ real part imaginary part
74+ 0.551685463458982E+00 0.125334886027721E+01
75+ 0.551685463458982E+00 -0.125334886027721E+01
76+ -0.149179798813990E+01 0.000000000000000E+00
77+ -0.805786469389031E+00 0.122290471337441E+01
78+ -0.805786469389031E+00 -0.122290471337441E+01
79+ ```
80+
3881## Compiling
3982
4083A ` fmp.toml ` file is provided for compiling polyroots-fortran with the [ Fortran Package Manager] ( https://github.com/fortran-lang/fpm ) . For example, to build:
0 commit comments