*
* @LagPolyRoots   lagpoly
*
* Produces a table of the inverted roots of the input lag polynomial,
* showing the modulus and (for complex roots) the period.
*
* Parameters:
*   lagpoly = polynomial represented as a VECTOR with
*      p(x)=v(1)+v(2)x+v(3)x**2+...+v(p+1)x**p
*
* Options:
*   TITLE=title for report ["Polynomial Roots"]
*
* Revision Schedule:
*   10/2005 Written by Tom Doan, Estima
*   09/2010 Switch to LOCAL REPORT
*
procedure LagPolyRoots lagpoly
type vector lagpoly
*
option string title
*
local integer 	i n
local vect[complex] roots
local report	rreport
local string	ltitle
*
compute n=%rows(lagpoly)-1
*
compute roots=%polycxroots(lagpoly)
ewise roots(i)=1.0/roots(i)
*
if %defined(title)
   compute ltitle=title
else
   compute ltitle="Polynomial Roots"

report(use=rreport,action=define,title=ltitle)
report(use=rreport,atrow=1,atcol=1,span) ltitle
report(use=rreport,atrow=2,atcol=1) "Real" "Imag" "Modulus" "Period"
do i=n,1,-1
   report(use=rreport,row=new,atcol=1) %real(roots(i)) %imag(roots(i)) %cabs(roots(i))
   if %imag(roots(i))<>0.0.and.%arg(roots(i))>0
      report(use=rreport,row=current,atcol=4) 2*%pi/%arg(roots(i))
end do i
report(use=rreport,action=format,atcol=1,tocol=4,picture="*.###")
report(use=rreport,action=show)
end

