Date:         Mon, 30 Apr 90 15:04:53 -0500
Reply-To:     HP-28 -  HP-28C and HP-28S Calculators <HP-28@@NDSUVM1>
Sender:       HP-28 -  HP-28C and HP-28S Calculators <HP-28@@NDSUVM1>
From:         Wayne H Scott <wscott@@EN.ECN.PURDUE.EDU>
Subject:      polynomials
To:           "Ulli Horlacher, Uni Ulm, W-Germany" <ASTA@@DULRUU51>
In-Reply-To:  CS300022%AUDUCVAX.BITNET@@VM1.NoDak.EDU's message of Mon,
              30 Apr 90 12:45:00 CDT <9004301834.AA01101@@en.ecn.purdue.edu>

I wrote the program that factors polynomials and it does divide polynomials
as well.  Here is a copy

This is poly version 2.

The first version of the polynomial root finder that I posted was slow and it
only worked on a 48sx without changes.  I have totally rewritten the solver
and now the main routine, BAIRS, is 3.8 times faster and 1/2 its previous size!

In addition, routines to do polynomal multiplication and division are now
included.  Have fun!

This file is set up to be downloaded into a HP48sx but the programs should

Please inform me of any bugs.


 The following is a set of programs that I developed to find the roots of
 polynomials.  However as a bonus I also created a program to reduce any
 polynomial into its quadratic factors.

 The first program is FCTP. (factor polynomial)
 When it is passed the cooeficients of a polynomial in a list it returns the
 factor of that polynomal.  ex:

 1: { 1 -17.8 99.41 -261.218 352.611 -134.106 }
 FCTP
 3: { 1 -4.2 2.1 }
 2: { 1 -3.3 6.2 }
 1: { 1 -10.3 }

 This tells us that X^5-17.8*X^4+99.41*X^3-261.218*X^2+352.611*X-134.106
 factors to (X^2-4.2*X+2.1)*(X^2-3.3*X+6.2)*(X-10.3)

 Neat!

 The next program is RT. (Roots)
 If given a polynmoial it return its roots.  ex:

 1: { 1 -17.8 99.41 -261.218 352.611 -134.106 }
 RT
 5: 3.61986841536
 4: .58013158464
 3: (1.65, 1.8648056199)
 2: (1.65, -1.8648056199)
 1: 10.3

 Very Useful!

 Another program that is included is PMUL to multiply two polys. ex:

 2: { 1 5 -7 }
 1: { 1 -5 }
 PMUL
 1: { 1 0 -32 35 }

 But wait theres more!  A program called PDIV is yours free just for trying
 this set of programs. Can you guess what it does?

 2: { 1 0 -32 36 }
 1: { 1 5 -7 }
 PDIV
 2: { 1 -5 }
 1: { 0 1 }

 This means that (X^3-32*X+35) / (X^2+5*X-7) = X-5 with remander 0*X+1

 These programs use the BAIRS program which performs Bairstow's method of
 quadratic factors and QUD with does the quadratic equation.

 Have Fun!
 _____________________________________________________________________________
 Wayne Scott            | INTERNET:   wscott@@en.ecn.purdue.edu
 Electrical Engineering | BITNET:     wscott%ea.ecn.purdue.edu@@purccvm
 Purdue University      | UUCP:      {purdue, pur-ee}!en.ecn.purdue.edu!wscott
 _____________________________________________________________________________
                "To iterate is human.  To recurse, divine."

 BAIR is described by the following code.  A(3) to A(n+3) is the polynomal
 and the result is { 1 -R -S }

 R = S = 1       ; inital guess
 B(1) = B(2) = C(1) = C(2) = 0
 DO
   FOR J = 3 TO n + 3
     B(J) = A(J) + R*B(J-1) + S*B(J-2)
     C(J) = B(J) + R*C(J-1) + S*C(J-2)
   NEXT J
   DEN = C(n+1)*C(n+1) - C(n+2)*C(n)
   IF DEN=0 THEN
       DELR = DELS = 1
   ELSE
       DELR = (B(n+3)*C(n) - B(n+2)*C(n+1))/DEN
       DELS = (C(n+2)*B(n+2) - C(n+1)*B(n+3))/DEN
   END
   R = R + DELR
   S = S + DELS
 UNTIL ABS(DELR) + ABS(DELS) < tol

