Find all the zeros (both real and complex conjugate) of a
polynomial with real coefficients.
----begin documentation----
		POLYNOMIAL SOLVER FOR THE TI-82

Michael Lloyd (lloydm@holly.hsu.edu)           October 1996
Henderson State University

This software is freeware.  I am in no way responsible for any loss
of money, data, or anything else from the use of this program.

Find all the zeros of a real polynomial.  The coefficients of the
polynomial are entered as a list starting with the highest ordered
term.  For example, 

			 3    2    
			x + 3x + 3x + 1

would be entered as {1,3,3,1}.  The tolerance is used to determine
when linear or quadratic pieces can be broken off of the polynomial.
If the polynomial has repeated roots, then the tolerance should not be
too small, or the program will run too long.  For the above example, a 
tolerance of .01 works fine.  It usually takes longer to find the
complex zeros.

The method was patterned after that used for the polynomial solver
which is built into the TI-85.  The matrix [A] is created which has
eigenvalues equal to the zeros of the polynomial.  The QR algorithm
is repeated, and a 2x2 or a 1x1 block is broken off of the bottom
of the iterated matrix.  The eigenvalues of the these blocks are 
approximate zeros for the polynomial.  During this QR process, the
diagonals of the iterated matrix are displayed.  The approximate real
zeros will appear in this list.

The QR process is iterated until the matrix [A] is gone, and then the
approximate complex zeros are displayed in the 2-column matrix [A]. After
that, the absolute values of the corresponding y-values are displayed in
the matrix [C].  Usually, the zeros are unacceptably innaccurate.  The
zeros can be repeatedly refined using a modified Newton's method which
converges quadratically, even at zeros with multiplicity > 1.  

The purpose of the QR algorithm step in this program is to get
approximations to the zeros of the polynomial which are sufficiently
accurate so that Newton's method will give every zero.

A,B,C,D,S,T = used somewhere
E,F,G = used in complex arithmetic
[A] = Hessenburg matrix, complex zeros
[B] = y-values
[C] = complex absolute-value of y-values
N = number of rows of matrix
L1 = polynomial coefficients
L2,L3 = used in computing the QR factorization
L4 = real part of zeros
L5 = imaginary part of zeros
R = degree of polynomial
W = tolerance
----end documentation----
----begin ASCII----
\START82\
\COMMENT=polynomial solver                         
\NAME=POLYSOLV
\FILE=polysolv.82P
ClrList \L2\,\L3\,\L4\,\L5\
ClrHome
Disp "INPUT POLY (\L1\)"
Input "{...}=",\L1\
dim \L1\-1\->\N
If N=0
Then
Disp "DEGREE MUST","BE > 0"
Stop
End
If \L1\(1)=0
Then
Disp "LEADING COEFF","MUST BE \<>\ 0"
Stop
End
Input "TOL= ",W
0\->\R:0\->\dim \L4\
\(-)\\L1\/\L1\(1)\->\\L1\
{1,N}\->\dim [A]
For(I,1,N)
\L1\(I+1)\->\[A](1,I)
End
{N,N}\->\dim [A]
For(I,2,N)
1\->\[A](I,I-1)
End
While N>2
For(K,1,N-1)
[A](K,K)\->\A
[A](K+1,K)\->\B
If B=0
Then
1\->\C:0\->\S
Else
If abs B\>=\abs A
Then
A/B\->\T
1/\sqrt\(1+T\^2\)\->\S
ST\->\C
Else
B/A\->\T
1/\sqrt\(1+T\^2\)\->\C
CT\->\S
End:End
C\->\\L2\(K)
S\->\\L3\(K)
For(J,K,N)
C[A](K,J)+S[A](K+1,J)\->\A
C[A](K+1,J)-S[A](K,J)\->\B
A\->\[A](K,J)
B\->\[A](K+1,J)
End:End
For(K,1,N-1)
\L2\(K)\->\C
\L3\(K)\->\S
For(I,1,K+1)
C[A](I,K)+S[A](I,K+1)\->\A
C[A](I,K+1)-S[A](I,K)\->\B
A\->\[A](I,K)
B\->\[A](I,K+1)
End:End
ClrHome
For(I,1,N)
Disp [A](I,I)
End
For(I,2,N)
If abs [A](I,I-1)\<=\W(abs [A](I-1,I-1)+abs [A](I,I))
0\->\[A](I,I-1)
End
If [A](N-1,N-2)=0
Then
[A](N-1,N-1)+[A](N,N)\->\B
[A](N-1,N-1)[A](N,N)-[A](N,N-1)[A](N-1,N)\->\C
B\^2\-4C\->\D
R+1\->\R
If D\>=\0
Then
\sqrt\D\->\D
(B+D)/2\->\\L4\(R)
0\->\\L5\(R)
R+1\->\R
(B-D)/2\->\\L4\(R)
0\->\\L5\(R)
Else
B/2\->\\L4\(R)
Ans\->\\L4\(R+1)
\sqrt\\(-)\D/2\->\\L5\(R)
\(-)\Ans\->\\L5\(R+1)
R+1\->\R
End
N-2\->\N
End
If N>1
Then
If [A](N,N-1)=0
Then
R+1\->\R
[A](N,N)\->\\L4\(R)
0\->\\L5\(R)
N-1\->\N
End:End:End
If N=2
Then
{2,2}\->\dim [A]
[A](1,1)+[A](2,2)\->\B
det [A]\->\C
B\^2\-4C\->\D
R+1\->\R
If D\>=\0
Then
\sqrt\D\->\D
(B+D)/2\->\\L4\(R)
0\->\\L5\(R)
R+1\->\R
(B-D)/2\->\\L4\(R)
0\->\\L5\(R)
Else
B/2\->\\L4\(R)
Ans\->\\L4\(R+1)
\sqrt\\(-)\D/2\->\\L5\(R)
\(-)\Ans\->\\L5\(R+1)
R+1\->\R
End
Else
R+1\->\R
[A](N,N)\->\\L4\(R)
0\->\\L5\(R)
End
{R,2}\->\dim [A]
{R,2}\->\dim [B]
{R,1}\->\dim [C]
2\->\dim \L2\
2\->\dim \L3\
For(I,1,R)
\L4\(I)\->\[A](I,1)
\L5\(I)\->\[A](I,2)
End
Lbl A
ClrHome
Disp "ZEROS ([A]):"
Pause [A]
Disp "abs OF","Y VALUES ([B]):"
For(I,1,R)
\L1\(1)\->\A
0\->\B
For(J,1,R)
A[A](I,1)-B[A](I,2)\->\C
A[A](I,2)+B[A](I,1)\->\B
C+\L1\(J+1)\->\A
End
A\->\[B](I,1)
B\->\[B](I,2)
End
For(I,1,R)
\sqrt\([B](I,1)\^2\+[B](I,2)\^2\)\->\[C](I,1)
End
Pause [C]
Disp "0 TO STOP"
Disp "1 TO REFINE"
Input T
If T=0
Then
ClrHome
Disp "ZEROS ([A]):"
Pause [A]
Stop
Else
For(I,1,R)
R\L1\(1)\->\A
0\->\B
For(J,1,R-1)
A[A](I,1)-B[A](I,2)\->\C
A[A](I,2)+B[A](I,1)\->\B
C+(R-J)\L1\(J+1)\->\A
End
A\->\\L2\(1)
B\->\\L2\(2)
R(R-1)\L1\(1)\->\A
0\->\B
For(J,1,R-2)
A[A](I,1)-B[A](I,2)\->\C
A[A](I,2)+B[A](I,1)\->\B
C+(R-J)(R-J-1)\L1\(J+1)\->\A
End
A\->\\L3\(1)
B\->\\L3\(2)
\L2\(1)\^2\-\L2\(2)\^2\-[B](I,1)\L3\(1)+[B](I,2)\L3\(2)\->\A
2\L2\(1)\L2\(2)-[B](I,1)\L3\(2)-[B](I,2)\L3\(1)\->\B
A\^2\+B\^2\\->\G
If G>0
Then
\L2\(1)[B](I,1)-\L2\(2)[B](I,2)\->\C
\L2\(1)[B](I,2)+\L2\(2)[B](I,1)\->\D
[A](I,1)-(AC+BD)/G\->\E
[A](I,2)-(AD-BC)/G\->\F
E\->\[A](I,1)
F\->\[A](I,2)
End:End:End
Goto A
----end ASCII----