44
55 program polyroots_test_10
66
7- use polyroots_module, only: dpolz, wp = > polyroots_module_rk
7+ use polyroots_module, only: polyroots, dpolz, wp = > polyroots_module_rk
88 use pyplot_module, only: pyplot
99
1010 implicit none
1111
12- integer ,parameter :: degree = 10 ! ! polynomial degree
13- integer ,dimension (* ),parameter :: icoeffs = [- 1 ,1 ] ! ! set of coefficients
14- integer ,dimension (degree+1 ) :: a ! ! coefficients of polynomial
15- real (wp),dimension (degree) :: zr, zi ! ! roots
12+ integer :: degree = 5 ! ! polynomial degree
13+ integer ,dimension (2 ) :: icoeffs = [- 1 ,1 ] ! ! set of coefficients
1614 integer :: ierr ! ! error code from [[dpolz]]
1715 type (pyplot) :: plt ! ! for making the plot
18-
19- call plt% initialize(grid= .true. ,xlabel= ' $\Re(z)$' ,ylabel= ' $\Im(z)$' ,&
20- title= ' Degree 10 Polynomial Roots' ,usetex= .true. ,&
21- figsize= [20 ,10 ])
22-
23- call generate(1 )
24- call plt% savefig(' roots.png' )
16+ integer :: i ,j
17+ character (len= 5 ) :: istr
18+ integer ,dimension (:),allocatable :: a ! ! coefficients of polynomial
19+ real (wp),dimension (:),allocatable :: zr, zi ! ! roots
20+
21+ do i = 2 , 10 , 2
22+
23+ write (istr,' (I5)' ) i; istr = adjustl (istr)
24+ degree = i
25+ ! resize
26+ a = [(0 , j = 1 , degree+1 )]
27+ zr = [(0 , j = 1 , degree)]
28+ zi = [(0 , j = 1 , degree)]
29+
30+ ! icoeffs = icoeffs + 1
31+ write (* ,* ) ' degree = ' , degree
32+ call plt% initialize(grid= .true. ,xlabel= ' $\Re(z)$' ,ylabel= ' $\Im(z)$' ,&
33+ title= ' Degree ' // trim (istr)// ' Polynomial Roots' ,usetex= .true. ,&
34+ font_size= 25 , axes_labelsize= 25 , &
35+ xtick_labelsize= 25 , ytick_labelsize= 25 , &
36+ figsize= [20 ,10 ])
37+ call generate(1 )
38+ call plt% savefig(' roots_' // trim (istr)// ' .png' )
39+
40+ end do
2541
2642 contains
2743
@@ -30,10 +46,11 @@ recursive subroutine generate (i)
3046 integer :: ix
3147 if (i > degree+1 ) then
3248 ! write (*, '(*(I2,","))') a
33- call dpolz(degree,real (a,wp),zr,zi,ierr); if (ierr/= 0 ) error stop ierr
34- call plt% add_plot(zr,zi,label= ' ' ,linestyle= ' bo' ,markersize= 1 )
49+ call polyroots(degree,real (a,wp),zr,zi,ierr) ! polyroots !! dpolz
50+ if (ierr/= 0 ) return ! error stop ierr
51+ call plt% add_plot(zr,zi,label= ' ' ,linestyle= ' bo' ,markersize= 2 )
3552 else
36- do ix = 1 ,size (icoeffs)
53+ do ix = 1 ,size (icoeffs)
3754 a(i) = icoeffs(ix)
3855 call generate(i+1 )
3956 end do
0 commit comments